Abuse
|
 |
«
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! 
|
|
|
Abuse
|
 |
«
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' 
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
Riven
|
 |
«
Reply #32 - Posted
2007-10-28 21:50:30 » |
|
Damn, this is too much fun.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Abuse
|
 |
«
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  )
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
Riven
|
 |
«
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.
|
|
|
|
Riven
|
 |
«
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; } |
|
|
|
|
Abuse
|
 |
«
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! 
|
|
|
Riven
|
 |
«
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. 
|
|
|
|
Abuse
|
 |
«
Reply #38 - Posted
2007-10-28 22:25:10 » |
|
A slightly more obfuscated version, unfortunately it's the same size  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! 
|
|
|
Riven
|
 |
«
Reply #39 - Posted
2007-10-28 22:31:32 » |
|
it's dead-easy to remove 1 byte by turning "b<<1" into "b*2" 
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Abuse
|
 |
«
Reply #40 - Posted
2007-10-28 22:41:49 » |
|
it's dead-easy to remove 1 byte by turning "b<<1" into "b*2"  *smacks forehead*
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
|
|
Abuse
|
 |
«
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! 
|
|
|
Riven
|
 |
«
Reply #43 - Posted
2007-10-28 23:25:20 » |
|
I tried, I tried  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 
|
|
|
|
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  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;} |
|
|
|
|
|
Riven
|
 |
«
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 
|
|
|
|
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  Would you post your version, just for my enlightment? 
|
|
|
|
|
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.
|
|
|
|
|
Abuse
|
 |
«
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 
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
|
|
Abuse
|
 |
«
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! 
|
|
|
Riven
|
 |
«
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)
|
|
|
|
Abuse
|
 |
«
Reply #52 - Posted
2007-10-29 01:12:58 » |
|
indeed, well stolen 
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
Abuse
|
 |
«
Reply #53 - Posted
2007-10-29 01:16:07 » |
|
ok, time to sleep  You've got until tomorrow to come up with some more challenges =)
|
Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! 
|
|
|
Riven
|
 |
«
Reply #54 - Posted
2007-10-29 01:16:20 » |
|
I'll try not to SSH into the server again. 
|
|
|
|
Riven
|
 |
«
Reply #55 - Posted
2007-10-29 01:17:30 » |
|
Tomorrow = exams for(int i=0; i<4; i++) After that... exams
|
|
|
|
Abuse
|
 |
«
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! 
|
|
|
Riven
|
 |
«
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) { 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??
|
|
|
|
Abuse
|
 |
«
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! 
|
|
|
Riven
|
 |
«
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  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.
|
|
|
|
|