TinyCode competition - trial

[quote=“Riven,post:56,topic:30806”]
Good luck - but hopefully you won’t need it!

Can anyone tell me why my read pointer is not advancing?


for(int a=in.read(),b=in.read();(a|b)>0;){
    out.write(b);
    out.write(a);
}

Whenever I run this, it just goes into an infinite loop. When I debug it, a and b keep reading the first 2 characters from the stream.

Consider: for(;;)…

is only executed ONCE and the beginning of the loop to initialize variables etc…

Ouch… :wink:

Two new assignments:
http://213.247.55.3:8484/compileandrun/?assignment=capitalizer
http://213.247.55.3:8484/compileandrun/?assignment=barcode

I made the barcode assignment extra hard by not adding a space at the end.

85 bytes for capitalizer, but that has to go shorter…
there are 3 variables in there…
who needs 3 variables anyway? :slight_smile:

for(int c,i=0,s=0; (c=in.read())>0 ; out.write(c-(i++==s & c > 96 & c < 123?32:0)))
      s =c == 32 ? i+1 : s;

for the barcode thingy 89 bytes

int i,c;
for(i=48;(c=in.read())>0;i=c==32?48:i+1)
   if(c==32)out.write(i);
if(i>0)out.write(i);

So lets start that shortening iteration again :slight_smile:

Edit:
capitalizer down to 7170:

for(int c,s=32; (c=in.read())>0;)
   out.write(s=c-(s==32 & c > 96 & c < 123?32:0));

barcode down to 66 bytes:

for(int c=1,i=48;c>0;i++){
  c=in.read();
  if(c<99){
    out.write(i);
    i=47;
  }
}

Capitalizer:


for(int c,s=32; (c=in.read())>0;)
out.write(s=s==c/96*32?c-s:c);

(61 bytes)

This was optimisation on the logic-level.
It didn’t have anything to do with reasoning.

I have yet to figure out how it works…

Thanks markush, for the jump-start.

We need another operator eh?


s=s*3          --->>> s*=3;
s=s==3?4:5;    --->>> s===3?4:5;

The above code works with the test case, but IMO doesn’t solve the spirit of the problem in all cases. :slight_smile:

Try it with a test case that includes the end conditions: e.g.

"@ 2pm { today }, I saw a bear at the zoo "

The above code would change the @ { } chars.

Here’s my current go @ Capitalizer:


for(int c, p = 32; (c = in.read()) > 0; )
 out.write( p = p == 32 & c > 96 & c < 123 ? c - p : c );

(67 bytes)

Cheers, Tim.

Yeah, I cheated. I removed the upper-bound check.

Yes… and the lower bound check is wrong… should be /97

I’ll cry myself to sleep tonight. :-[

BinaryShrink


for( int v = 1; (v += v + in.read() % 2) > 1; )
  if( v > 255 )
  {
    out.write( v );
    v = 1;
  }

(61 bytes)

doh :-[

Thanks.

67 bytes:

out.write(new byte[] { 50,51,56,49,52,57,54,50,51,49,49,50,48,49,51 });

:wink:

I’ll add a bunch of testcases to each assignment, when I have time for it.

hey Riven, I killed your server ;D


com.sun.org.apache.regexp.internal.recompile.main("".split(""));

(64 bytes)

;D

WHAAAA

It was worse than you might every have thought…

There was a piece of user-submitted sourcecode processed by BASH… :o :o :o

That’s like total control…

http://www.indiespot.net/hacked.png

I’m not going to launch the http-server until I fixed this…

Hm… there is a System.exit(0) inside that method…

I really can’t understand how that System.out (!!!) could end up in bash.

I mean… after System.exit(0) is called, the JVM is supposed to be dead, and everything that was buffered in System.out should be discarded, not writting into STDIN…

Anybody?

yeah, it was the System.exit(0); that I was exploiting to terminate the vm…
Took me ages to think of a way to pass in a String[], to get the desired effect :slight_smile:

What was it that was written to stdin?
the socket input stream? or system.out?

Can you reproduce it?

Seems like a serious vm bug to me, it isn’t like my code did anything that a normal java service couldn’t do as the result of some kind of unrecoverable error.
Presumably it’s the result of a thread race condition, as I guess our provided code is executing on it’s own thread?