Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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 4 ... 6
  ignore  |  Print  
  TinyCode competition - trial  (Read 27232 times)
0 Members and 1 Guest are viewing this topic.
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #30 - Posted 2007-10-28 21:42:50 »

Oops - 2 too many parenthesis!
Down still further, to 64bytes!
1  
2  
3  
4  
5  
6  
7  
for(int
b=1;
(b=b<<1|in.read()-48)>0;)
if(b>255){
out.write(b);
b=1;
}

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

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #31 - Posted 2007-10-28 21:45:14 »

"(b=b<<1|in.read()-48)>0"

*shudder*

A serious case of 'know thy operator precedence' Grin

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #32 - Posted 2007-10-28 21:50:30 »

Damn, this is too much fun.

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 Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #33 - Posted 2007-10-28 21:54:13 »

Damn, this is too much fun.

And we havn't even moved onto the hex string problem :|
I fear that is going to be realy horrible!

Tomorrow, I'll point a few of the guys @ work to this Thread;
it's a mobile phone games company, so they're usually up for a ludicrous micro-optimisation challenge! (though normally @ the bytecode, not source-code level Cheesy)

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #34 - Posted 2007-10-28 21:58:39 »

I added a "hex-viewer" at the bottom, so you can check your 'invisible' output too.

I honestly didn't know about the trailing 0-byte in my 72 solution.

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #35 - Posted 2007-10-28 22:08:23 »

I decided to remove all whitespace from the byte-count, even spaces required to compile:
[int a,b,c;] is counted as [inta,b,c;]

I mean... we can all remove new lines and spaces... that's not where the focus should be.

As an exampe, this is 64 bytes now:
1  
2  
3  
4  
5  
6  
for(int b=1;(b=b<<1|in.read()-48)>0;)
  if(b>255)
  {
     out.write(b);
     b=1;
  }

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #36 - Posted 2007-10-28 22:12:26 »

Fair enough, though it does make declaring types 1 byte cheaper than they should otherwise be.

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #37 - Posted 2007-10-28 22:15:43 »

The spaces could ALL be eliminated by line-breaks..

Otherwise I need to write a pretty darn clever byte-counter, or count linebreaks again, but then i could as well use a textfield instead of a textarea. Lips Sealed

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #38 - Posted 2007-10-28 22:25:10 »

A slightly more obfuscated version, unfortunately it's the same size Sad

1  
2  
3  
for(int b=1;(b=b<<1|in.read()-48)>0;)
for(;b>255;b=1)
out.write(b);

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #39 - Posted 2007-10-28 22:31:32 »

it's dead-easy to remove 1 byte by turning "b<<1" into "b*2" Wink

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 Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #40 - Posted 2007-10-28 22:41:49 »

it's dead-easy to remove 1 byte by turning "b<<1" into "b*2" Wink

*smacks forehead*

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #41 - Posted 2007-10-28 23:16:47 »

http://213.247.55.3:8484/compileandrun/?assignment=hex
1  
2  
for(int a,s=1;(a=in.read())>0;)
if((s=s*16+(a<58?a-48:a-87))>255){out.write(s);s=1;}

(82 bytes)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #42 - Posted 2007-10-28 23:24:15 »

Can you not reduce the size of those numeric constants by including the -48 in the (a=in.read())>0 ?

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #43 - Posted 2007-10-28 23:25:20 »

I tried, I tried Cry


Hex:
1  
2  
for(int a,s=1;s>0;s=s*16|((a=in.read())<58?a-48:a-87))
if(s>255){out.write(s);s=1;}

(81 bytes)


BinaryShrink:
1  
2  
for(int b=1;b>0;b=b*2|in.read()-48)
if(b>255){out.write(b);b=1;}

(62 bytes)


Look how much they look alike Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline markush

Senior Newbie




Plöp!


« Reply #44 - Posted 2007-10-28 23:53:59 »


Hex:
1  
2  
for(int a,s=1;s>0;s=s*16|((a=in.read())<58?a-48:a-87))
if(s>255){out.write(s);s=1;}

(81 bytes)

another one bytes the dust: 80 bytes Smiley

1  
2  
for(int a,s=1;s>0;s=s*16|-((a=in.read())<58?48:87)+a)
if(s>255){out.write(s);s=1;}


Edit:

Got another one for 79 bytes
1  
2  
for(int a,s=1;s>0;s=s*16|(a=in.read())-(a<58?48:87))
if(s>255){out.write(s);s=1;}
Online Riven
« League of Dukes »

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #45 - Posted 2007-10-29 00:01:54 »

Yeah, I saw you moving from 81 to 80 bytes on the server.
Then I made a 79 using your version, but I didn't dare to post it, because it felt like cheating.
But now that you posted it, all I can say is that I did it slightly different... but you get the credit Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline markush

Senior Newbie




Plöp!


« Reply #46 - Posted 2007-10-29 00:03:43 »

Yeah, I saw you moving from 81 to 80 bytes on the server.
Then I made a 79 using your version, but I didn't dare to post it, because it felt like cheating.
But now that you posted it, all I can say is that I did it slightly different... but you get the credit Smiley

Would you post your version, just for my enlightment? Smiley
Offline markush

Senior Newbie




Plöp!


« Reply #47 - Posted 2007-10-29 00:45:11 »

We need no stinking a variable:

1  
2  
for(int s=1;s>0;s=s*16|(s=in.read())-(s<58?48:87))
if(s>255){out.write(s);s=1;}


That makes it 77 bytes.
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #48 - Posted 2007-10-29 00:48:59 »

ouch, nested self-assignment - now things *are* getting complicated =)

If I saw that in some production code I would likely have to beat someone to death Grin

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #49 - Posted 2007-10-29 00:53:45 »

I'm getting beaten at my own game. Angry



Cry

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #50 - Posted 2007-10-29 00:55:22 »

We need no stinking a variable:

1  
2  
for(int s=1;s>0;s=s*16|(s=in.read())-(s<58?48:87))
if(s>255){out.write(s);s=1;}


That makes it 77 bytes.

I'm playing with changing the conditional operator (s<58?48:87) for an arithmetic/shift solution, so that the additional parenthesis can be eliminated..
Doing it without breaking the end condition s>0 is the hard part......
ah, is that what you did for your 79byte version Riven? ".....in.read()-48)-(s/49)*39" ?


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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #51 - Posted 2007-10-29 01:11:22 »

You (who?) did it, you just need to "-(s/49)*" >>> "-s/49*"

1  
2  
for(int s=1;s>0;s=s*16|(s=in.read()-48)-s/49*39)
if(s>255){out.write(s);s=1;}

(75 bytes)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #52 - Posted 2007-10-29 01:12:58 »

indeed, well stolen  Tongue

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

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #53 - Posted 2007-10-29 01:16:07 »

ok, time to sleep Grin

You've got until tomorrow to come up with some more challenges =)

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #54 - Posted 2007-10-29 01:16:20 »

I'll try not to SSH into the server again. Kiss

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #55 - Posted 2007-10-29 01:17:30 »

Tomorrow = exams
for(int i=0; i<4; i++)
   After that... exams

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #56 - Posted 2007-10-29 01:22:46 »


Gotta say, your first targets were pretty damn good!
It's taken 4 people, and a dozen or so iterations to get them down to 62 & 75 bytes respectively!

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #57 - Posted 2007-10-29 01:23:39 »

If anybody has a fancy idea...

This is how I implmented the hex-assignment:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
public class HexTinyCodeAssignment extends TinyCodeAssignment
{
   @Override
   public String getName()
   {
      return "hex";
   }

   @Override
   public String getTitle()
   {
      return "Hex";
   }

   @Override
   public String getDescription()
   {
      return "There are values encoded into hexadecimals, turn them into bytes again";
   }

   @Override
   public String getExample()
   {
      return "'6e64' -> 'nd'";
   }

   @Override
   public byte[] createQuestion()
   {
      return str2arr("72616e646f6d206d61726b65722036");
   }
   
   @Override
   public String getDefaultSource()
   {
      StringBuilder sb = new StringBuilder();
      sb.append("while (true)\n");
      sb.append("{\n");
      sb.append("   int a = in.read();\n");
      sb.append("   int b = in.read();\n");
      sb.append("   if ((a | b) == -1)\n");
      sb.append("       break;\n");
      sb.append("   int ai = (a <= '9') ? (a-'0') : (a-'a'+10);\n");
      sb.append("   int bi = (b <= '9') ? (b-'0') : (b-'a'+10);\n");
      sb.append("   out.write(ai * 16 + bi);\n");
      sb.append("}");
      return sb.toString();
   }

   @Override
   public void processCorrectly(InputStream in, OutputStream out) throws IOException
   {
      while (true)
      {
         int a = in.read();
         int b = in.read();
         if ((a | b) == -1)
            break;
         int ai = (a <= '9') ? (a-'0') : (a-'a'+10);
         int bi = (b <= '9') ? (b-'0') : (b-'a'+10);
         out.write(ai * 16 + bi);
      }
   }
}



Post your TinyCodeAssignment subclass !


This is the class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
public abstract class TinyCodeAssignment
{
   public abstract String getName();

   public abstract String getTitle();

   public abstract String getDescription();

   public abstract String getExample();

   public abstract byte[] createQuestion();

   public abstract String getDefaultSource();

   public abstract void processCorrectly(InputStream in, OutputStream out) throws IOException;

   public final byte[] createAnswer(byte[] question)
   {
      try
      {
         InputStream in = new ByteArrayInputStream(question);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         this.processCorrectly(in, out);
         return out.toByteArray();
      }
      catch (IOException exc)
      {
         // never happens
        throw new RuntimeException(exc);
      }
   }

   public final boolean isValid(byte[] correctAnswer, byte[] userAnswer)
   {
      if (correctAnswer.length != userAnswer.length)
         return false;
      for (int i = 0; i < correctAnswer.length; i++)
         if (correctAnswer[i] != userAnswer[i])
            return false;
      return true;
   }

   public static final String arr2str(byte[] arr)
   {
      try
      {
         return new String(arr, "ASCII");
      }
      catch (UnsupportedEncodingException exc)
      {
         throw new RuntimeException(exc);
      }
   }

   public static final byte[] str2arr(String str)
   {
      try
      {
         return str.getBytes("ASCII");
      }
      catch (UnsupportedEncodingException exc)
      {
         throw new RuntimeException(exc);
      }
   }
}


Poll: Can I get away with posting pages of code??

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #58 - Posted 2007-10-29 01:30:30 »

Is your server keeping track of what the best submitted solution is for each assignment?
It's be nice if we could see the bytesize of the current best, and maybe the solution after say 1 hour. (so they get their 60 minutes of glory =D)

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

JGO Overlord


Medals: 606
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #59 - Posted 2007-10-29 01:38:01 »

I'm awefully busy with... joining my own contest, building the server, watching SSH scroll by, and studying for exams Smiley


I've got the MySQL instance setup, with database/tables, but it aint yet connected...

I'm used to programming this stuff in PHP, and I gotta say that Java is a bit annoying here...
I had to build a dynamic classloader that grabs the latest JARs and runs them.
There aint no CTRL+S, F5 here. Bah.

And I really miss the multi-line strings...
1  
2  
3  
4  
5  
txt = <<<EOF
SELECT *
FROM ..
WHERE id = 3
EOF;

And the more I use PHP, the weirder the + operator looks for concatenating Strings in Java..

How do you guys program a website in Java!!! Aaahhh!!


Anyway, to answer your question: I'm the only one keeping track of anything. I think i'm just going to make it functional. Just that, and don't give a crap about the looks.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: 1 [2] 3 4 ... 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.

xsi3rr4x (64 views)
2014-04-15 18:08:23

BurntPizza (62 views)
2014-04-15 03:46:01

UprightPath (75 views)
2014-04-14 17:39:50

UprightPath (58 views)
2014-04-14 17:35:47

Porlus (76 views)
2014-04-14 15:48:38

tom_mai78101 (101 views)
2014-04-10 04:04:31

BurntPizza (161 views)
2014-04-08 23:06:04

tom_mai78101 (256 views)
2014-04-05 13:34:39

trollwarrior1 (209 views)
2014-04-04 12:06:45

CJLetsGame (216 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!