Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2 3 ... 6
  Print  
  TinyCode competition - trial  (Read 20358 times)
0 Members and 4 Guests are viewing this topic.
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« on: 2007-10-27 18:12:04 »

I'm tempted to host some silly competion thingy about writing the smallest code to perform some I/O task.

I coded some really silly task, and I'd like you guys to check out whether there is anything dangerous possible.
If so, I'd be very grateful if you'd let me know as fast as possible.
I'm renting this server, and I wouldn't really like to get my account suspended.

I tried to isolate the running of tasks as much as possible, within the current JVM, but I might have to resort launching a new JVM to avoid any corruption of the HTTP-server-instance hosting this.

http://213.247.55.3:8484/compileandrun/


A (naive) solution for the task would be:
1  
2  
3  
4  
5  
6  
7  
8  
while(true)
{
  int a = in.read();
  int b = in.read();
  if((a|b)<0) break;
  out.write(b);
  out.write(a);
}

108 bytes, linebreaks don't count (for readability reasons), but spaces do

Beat that! I didn't really raise the bar very high, did I.. Smiley


Anyway, give it a try, and tell me if there's something I need to know. Kiss

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #1 on: 2007-10-27 18:20:50 »

Beat 62 bytes, and don't forget to be naughty.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #2 on: 2007-10-27 18:52:37 »

I disabled uppercase characters... to catch the casual tester
1  
System.exit(0);



This worked though:
1  
\u0053ystem.exit(0);



Gimme your tricks..

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Games published by our own members! Go get 'em!
Offline kappa
« League of Dukes »

JGO Kernel
*****

Posts: 2360
Medals: 59


★★★★★


« Reply #3 on: 2007-10-27 20:12:51 »

ewww, no uppercase characters  Embarrassed, pretty much ends it for me.
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #4 on: 2007-10-27 20:35:24 »

Hey... how else would I keep it secure...

and... why would you need Classes in such tasks?



I'm glad you tried it though Smiley

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #5 on: 2007-10-27 20:36:35 »

Beat 62 bytes, and don't forget to be naughty.

Got to 64bytes so far....
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #6 on: 2007-10-27 20:40:28 »

Way to go!

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline kappa
« League of Dukes »

JGO Kernel
*****

Posts: 2360
Medals: 59


★★★★★


« Reply #7 on: 2007-10-27 20:42:59 »

and... why would you need Classes in such tasks?

ah sorry my mistake, thought the task was to break the program Smiley
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #8 on: 2007-10-27 20:45:07 »

That too... Grin and that stops like 99.9999% of all attacks.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #9 on: 2007-10-27 21:53:23 »

Got to 64bytes so far....

Haha, I'm such a muppet - that 64byte solution was actually 62bytes =)
I hadn't removed the declaration of the now unused b integer Cheesy

Can't see a way of beating 62 though... atleast not yet =)
Games published by our own members! Go get 'em!
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #10 on: 2007-10-27 21:56:23 »

Darn.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #11 on: 2007-10-27 22:21:05 »

A dead end... but I love it!

1  
for(byte[]b={0,0,1};in.read(b,b[2]++&1,1)>0;out.write(b,0,b[2]*2&2));

(69 bytes)

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #12 on: 2007-10-27 22:56:17 »

A dead end... but I love it!

1  
for(byte[]b={0,0,1};in.read(b,b[2]++&1,1)>0;out.write(b,0,b[2]*2&2));

(69 bytes)

If you are going to break the defined contract of InputStream.read(byte[],int,int), by only checking for ">0" on the return type, then the 62 byte solution mentioned earlier can be trimmed to 61 bytes =)
(presumably your own 6[1/2] byte solution is exactly the same as mine?)

1  
for(int a;(a=in.read())>0;out.write(in.read()),out.write(a));

Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #13 on: 2007-10-27 22:59:37 »

>0 is not breaking the contract of InputStream.read(byte[],int,int)

Quote
This method blocks until input data is available, end of file is detected, or an exception is thrown.

it will never ever return 0.

Unless your set the thrid argument to 0 Wink

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline noblemaster

JGO Ninja
***

Posts: 730
Medals: 6


Age of Conquest makes your day!


« Reply #14 on: 2007-10-27 23:00:35 »

actually, I got 1 byte less (60 bytes):
1  
for(int a;(a=in.read())>0;out.write(a))out.write(in.read());

ditto Abuse it's 61 bytes if you use >=0...

Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #15 on: 2007-10-27 23:02:53 »

I guess this is good enough to turn into a bigger project Smiley

I wrote the http-server myself, so pretty much everything is possible.

Again, don't forget to mention the security-holes. Thank you.


Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #16 on: 2007-10-27 23:04:44 »

Quote
1  
for(int a;(a=in.read())>0;out.write(a))out.write(in.read());

I totally love the simplicity.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #17 on: 2007-10-27 23:06:57 »

oh yeah, nice spot  Grin
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #18 on: 2007-10-27 23:08:38 »

I totally love the simplicity.

I still think your 69byte solution is by far the most complicated =S
Offline Matzon
« League of Dukes »

JGO Kernel
*****

Posts: 1805
Medals: 8


I'm gonna wring your pants!


« Reply #19 on: 2007-10-28 03:52:32 »

isn't this flawed, since it only checks the validity of the first in.read?
-edit- ok, the string has pairs of bytes.

http://certusgames.com (Free Online Multiplayer Java Games)
http://lwjgl.org (OpenGL/OpenAL for Java)
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #20 on: 2007-10-28 11:07:04 »

Second assignment available:
http://213.247.55.3:8484/compileandrun/?assignment=binaryshrink
73 bytes...


Third assignment available:
http://213.247.55.3:8484/compileandrun/?assignment=hex
86 bytes...

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #21 on: 2007-10-28 12:28:15 »

I'm adding a database now, to make accounts, and compete against eachother...

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline markush

Jr. Member
**

Posts: 52


Plöp!


« Reply #22 on: 2007-10-28 15:04:40 »


72 bytes! muhahaha Smiley

To achieve it, you can replace the only space with a line break, and since that doesn't count its one byte off Smiley
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #23 on: 2007-10-28 15:12:55 »

Hehe... then I get 72 bytes too...

and I got 2 solutions:
1  
2  
3  
for(int
r=0,i=0,b=0;r>-1;b=b<<1|(r=in.read())&1)
if(i++%8==0)out.write(b);

1  
2  
3  
4  
5  
6  
for(int
r,i=0,b=0;(r=in.read())>0;)
{
b=b<<1|r&1;
if(++i%8==0)out.write(b);
}


The first is extremely not-done.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #24 on: 2007-10-28 15:15:33 »

It's a nice loophole though, and I'll make sure I'll 'fix' that.

Like... only linebreaks allowed after a '{'



Could you show me your solution?

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline markush

Jr. Member
**

Posts: 52


Plöp!


« Reply #25 on: 2007-10-28 15:24:54 »

Hehe... then I get 72 bytes too...

and I got 2 solutions:
1  
2  
3  
for(int
r=0,i=0,b=0;r>-1;b=b<<1|(r=in.read())&1)
if(i++%8==0)out.write(b);

1  
2  
3  
4  
5  
6  
for(int
r,i=0,b=0;(r=in.read())>0;)
{
b=b<<1|r&1;
if(++i%8==0)out.write(b);
}


The first is extremely not-done.

My is a bit different:

1  
2  
3  
4  
5  
for(int
c=0,i=0,x;(x=in.read())>0;c<<=1){
c|=x&1;
if(++i%8<1)out.write(c);
}


And 71 bytes with that:
1  
2  
3  
for(int
r=1,i=0,b=0;r>0;b=b<<1|(r=in.read())&1)
if(i++%8==0)out.write(b);
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #26 on: 2007-10-28 15:56:46 »

erm, am I missing something?
2 of the solutions above don't work?

They output a leading 0 to the output stream.

1  
2  
3  
for(int
r=1,i=0,b=0;r>0;b=b<<1|(r=in.read())&1)
if(i++%8==0)out.write(b);


and

1  
2  
3  
for(int
r=0,i=0,b=0;r>-1;b=b<<1|(r=in.read())&1)
if(i++%8==0)out.write(b);
Offline Martin Strand

Jr. Member
**

Posts: 60



« Reply #27 on: 2007-10-28 16:13:20 »

This doesn't output a leading zero but all ascii values are 0x100 too high. It looks ok on that web page though. Cheesy  (70 bytes)
1  
2  
3  
4  
5  
6  
7  
8  
9  
for(int
r=1,b=1;
r>0;
b=b<<1|(r=in.read())&1)
if(b>255)
{
out.write(b);
b=1;
}
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #28 on: 2007-10-28 16:29:01 »

This doesn't output a leading zero but all ascii values are 0x100 too high. It looks ok on that web page though. Cheesy  (70 bytes)
1  
2  
3  
4  
5  
6  
7  
8  
9  
for(int
r=1,b=1;
r>0;
b=b<<1|(r=in.read())&1)
if(b>255)
{
out.write(b);
b=1;
}


That's perfectly ok - the contract of OutputStream.write(int) dictates that only the bottom 8 bits are used anyway, so using the upper bits for signalling is pretty damn clever =)
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #29 on: 2007-10-28 16:37:19 »

An adaption of the above (66 bytes!) :-

Quote
for(int
b=1;
(b=b<<1|(in.read()-48))>0;)
if(b>255){
out.write(b);
b=1;
}

And there is even a redundant ';' in the for, which I'm sure can be optimised away with some restructuring?
Pages: [1] 2 3 ... 6
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.123 seconds with 17 queries.