SimonH
|
 |
«
Reply #60 - Posted
2007-10-29 02:01:10 » |
|
Tomorrow = exams Good luck - but hopefully you won't need it!
|
|
|
|
CaptainJester
|
 |
«
Reply #61 - Posted
2007-10-29 03:40:17 » |
|
Can anyone tell me why my read pointer is not advancing? 1 2 3 4
| 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.
|
|
|
|
noblemaster
|
 |
«
Reply #62 - Posted
2007-10-29 06:00:56 » |
|
Consider: for(<part1>;<part2>;<part3>)...
<part1> is only executed ONCE and the beginning of the loop to initialize variables etc...
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Riven
|
 |
«
Reply #63 - Posted
2007-10-29 09:58:42 » |
|
|
|
|
|
markush
Senior Newbie 
Plöp!
|
 |
«
Reply #64 - Posted
2007-10-29 10:30:06 » |
|
85 bytes for capitalizer, but that has to go shorter... there are 3 variables in there... who needs 3 variables anyway?  1 2
| 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 1 2 3 4
| 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  Edit: capitalizer down to 7170: 1 2
| 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: 1 2 3 4 5 6 7
| for(int c=1,i=48;c>0;i++){ c=in.read(); if(c<99){ out.write(i); i=47; } } |
|
|
|
|
|
Riven
|
 |
«
Reply #65 - Posted
2007-10-29 12:01:44 » |
|
Capitalizer: 1 2
| 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.
|
|
|
|
Riven
|
 |
«
Reply #66 - Posted
2007-10-29 12:11:43 » |
|
We need another operator eh? 1 2
| s=s*3 --->>> s*=3; s=s==3?4:5; --->>> s===3?4:5; |
|
|
|
|
timfoden
|
 |
«
Reply #67 - Posted
2007-10-29 12:28:32 » |
|
Capitalizer: 1 2
| for(int c,s=32; (c=in.read())>0;) out.write(s=s==c/96*32?c-s:c); |
(61 bytes) The above code works with the test case, but IMO doesn't solve the spirit of the problem in all cases.  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: 1 2
| 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.
|
|
|
|
Riven
|
 |
«
Reply #68 - Posted
2007-10-29 12:31:34 » |
|
Yeah, I cheated. I removed the upper-bound check.
|
|
|
|
timfoden
|
 |
«
Reply #69 - Posted
2007-10-29 12:38:35 » |
|
Yeah, I cheated. I removed the upper-bound check.
Yes... and the lower bound check is wrong... should be /97
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Riven
|
 |
«
Reply #70 - Posted
2007-10-29 12:46:07 » |
|
I'll cry myself to sleep tonight. 
|
|
|
|
timfoden
|
 |
«
Reply #71 - Posted
2007-10-29 14:30:14 » |
|
BinaryShrink 1 2 3 4 5 6
| for( int v = 1; (v += v + in.read() % 2) > 1; ) if( v > 255 ) { out.write( v ); v = 1; } |
(61 bytes)
|
|
|
|
CaptainJester
|
 |
«
Reply #72 - Posted
2007-10-29 14:43:21 » |
|
Consider: for(<part1>;<part2>;<part3>)...
<part1> is only executed ONCE and the beginning of the loop to initialize variables etc...
doh  Thanks.
|
|
|
|
Mr_Light
|
 |
«
Reply #73 - Posted
2007-10-29 18:35:28 » |
|
barcode down to 66 bytes: 1 2 3 4 5 6 7
| for(int c=1,i=48;c>0;i++){ c=in.read(); if(c<99){ out.write(i); i=47; } } |
67 bytes: 1
| out.write(new byte[] { 50,51,56,49,52,57,54,50,51,49,49,50,48,49,51 }); |

|
It's harder to read code than to write it. - it's even harder to write readable code.
The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
|
|
|
Riven
|
 |
«
Reply #74 - Posted
2007-10-29 20:30:12 » |
|
I'll add a bunch of testcases to each assignment, when I have time for it.
|
|
|
|
Abuse
|
 |
«
Reply #75 - Posted
2007-10-30 00:27:20 » |
|
hey Riven, I killed your server  1
| com.sun.org.apache.regexp.internal.recompile.main("".split("")); |
(64 bytes)
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
|
|
Riven
|
 |
«
Reply #77 - Posted
2007-10-30 01:24:44 » |
|
WHAAAA It was worse than you might every have thought... There was a piece of user-submitted sourcecode processed by BASH...  That's like total control... 
|
|
|
|
Riven
|
 |
«
Reply #78 - Posted
2007-10-30 01:29:01 » |
|
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?
|
|
|
|
Abuse
|
 |
«
Reply #79 - Posted
2007-10-30 01:43:12 » |
|
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 :-)
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?
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
Riven
|
 |
«
Reply #80 - Posted
2007-10-30 02:00:35 » |
|
User-sourcecode is compiled by janino. The compiled sourcecode cannot be sent to STDIN, because it only exists in bytecode-form. I do a System.out.println(code); to monitor the submission you guys post. Unfortunately, to enforce the time-limit of 100ms, I have to call Thread.stop() if the newly created thread running your code, runs out of time. Now... before I even can call stop(), the System.exit(0) is already executed, so I doubt the problem is in that 'unsafe' method. It feels like this was the actual chain of events: 1. System.out.println(code); 2. new Thread(){public void run(){System.exit(0);}}.start(); Result: the bytes buffered in STDOUT get flushed to STDIN after termination. Is it correct that you submitted this full block of code? 1 2 3 4 5 6 7
| com.sun.org.apache.regexp.internal.recompile.main("".split("")); out.write(str2arr("hello world!")); int a=0,i=0,b; while((b=in.read())>0) { a=a<<4|(b-'0'); if ((i^=1)==0) out.write(a); } |
|
|
|
|
Abuse
|
 |
«
Reply #81 - Posted
2007-10-30 02:04:55 » |
|
nope, I only submitted
"com.sun.org.apache.regexp.internal.recompile.main("".split(""));"
The rest is nothing to do with me, never seen it before in my life. "byte [] str2arr(String)" is one of your methods isn't it? declared in TinyCodeAssignment. Was that just someone attempting to access this method from their own code?
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
Abuse
|
 |
«
Reply #82 - Posted
2007-10-30 02:06:57 » |
|
The compiled sourcecode cannot be sent to STDIN, because it only exists in bytecode-form. I was thinking more of the source code that is embedded in the html page served back to the client?
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
Riven
|
 |
«
Reply #83 - Posted
2007-10-30 02:07:10 » |
|
It was part of the sourcecode I posted in this thread (many many lines).
Somebody thought he could access the str2arr or arr2str because it was defined in the posted TinyCodeAssignment class.
|
|
|
|
Riven
|
 |
«
Reply #84 - Posted
2007-10-30 02:09:23 » |
|
The code sent back to the client doesn't have < and >, only < and > to prevent HTML-tags (and scripts!) breaking out of the <textarea></textarea>
|
|
|
|
Riven
|
 |
«
Reply #85 - Posted
2007-10-30 02:12:45 » |
|
Anyway, as you can see in the screenshot, the JVM is shutdown after your one-line submission, yet the next (?) submission is executed in BASH...
I'll investigate tomorrow, and go to bed now. It's 02:00, and I got yet another exam tomorrow.
|
|
|
|
Abuse
|
 |
«
Reply #86 - Posted
2007-10-30 02:25:42 » |
|
Eagerly awaiting my gold 'I crashed the server' badge 
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
Riven
|
 |
«
Reply #87 - Posted
2007-10-30 02:31:53 » |
|
Bah, I didn't go to bed!  I found it... it wasn't that spooky. If you type something in Bash, while a program is running, it's sent to STDIN. If you type CTRL-C, the bytes in System.in are discarded. If System.exit(0) is invoked, the bytes in System.in are passed to STDIN of Bash (as in: if the child-process doesn't handle it, the parent process will) So... it turned out I probably pasted that code accidently yesterday, and never noticed. (...working on the badge)
|
|
|
|
Riven
|
 |
«
Reply #88 - Posted
2007-10-30 02:53:44 » |
|
|
|
|
|
Riven
|
 |
«
Reply #89 - Posted
2007-10-30 03:33:26 » |
|
I'm hosting it again, now allowing uppercase characters, but no unicode. It only allows a "." if it is followed by "read(" or "write(". I think this should catch all random acts of vandalism Please report exploits... in private-mail on jgo
|
|
|
|
|