Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2 3 ... 6
  ignore  |  Print  
  TinyCode competition - trial  (Read 27641 times)
0 Members and 1 Guest are viewing this topic.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Posted 2007-10-27 22: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
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2007-10-27 22: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
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2007-10-27 22: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 75
Projects: 15


★★★★★


« Reply #3 - Posted 2007-10-28 00:12:51 »

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

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2007-10-28 00: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 Knight


Medals: 12


falling into the abyss of reality


« Reply #5 - Posted 2007-10-28 00:36:35 »

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

Got to 64bytes so far....

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2007-10-28 00: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


Medals: 75
Projects: 15


★★★★★


« Reply #7 - Posted 2007-10-28 00:42:59 »

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

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

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2007-10-28 00: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 Knight


Medals: 12


falling into the abyss of reality


« Reply #9 - Posted 2007-10-28 01: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 =)

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2007-10-28 01:56:23 »

Darn.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2007-10-28 02: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 Knight


Medals: 12


falling into the abyss of reality


« Reply #12 - Posted 2007-10-28 02: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));


Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2007-10-28 02: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


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #14 - Posted 2007-10-28 03: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...

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #15 - Posted 2007-10-28 03: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
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2007-10-28 03: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 Knight


Medals: 12


falling into the abyss of reality


« Reply #17 - Posted 2007-10-28 03:06:57 »

oh yeah, nice spot  Grin

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #18 - Posted 2007-10-28 03:08:38 »

I totally love the simplicity.

I still think your 69byte solution is by far the most complicated =S

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #19 - Posted 2007-10-28 07: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.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #20 - Posted 2007-10-28 15: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
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #21 - Posted 2007-10-28 16: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

Senior Newbie




Plöp!


« Reply #22 - Posted 2007-10-28 19: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
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #23 - Posted 2007-10-28 19: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
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #24 - Posted 2007-10-28 19: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

Senior Newbie




Plöp!


« Reply #25 - Posted 2007-10-28 19: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 Knight


Medals: 12


falling into the abyss of reality


« Reply #26 - Posted 2007-10-28 19: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);

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Martin Strand

Junior Member





« Reply #27 - Posted 2007-10-28 20: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 Knight


Medals: 12


falling into the abyss of reality


« Reply #28 - Posted 2007-10-28 20: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 =)

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #29 - Posted 2007-10-28 20: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?

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Pages: [1] 2 3 ... 6
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!