Calculator Community > Community Contests

[ENDED] Code Golf Contest #2

<< < (6/6)

ben_g:

--- Quote from: 3298 on July 28, 2014, 02:51:23 pm ---Looking over the solutions, I noticed that the shortest Java version does not process one string, but instead assumes someone has split it already

--- End quote ---
That's because java automatically splits the input, as long as the input string is not surrounded by quotes.

By the way, I had a smaller version, but I have been quite busy with other projects and I forgot to submit that one. Anyway, here was that code (169 bytes):
--- Code: ---class C{public static void main(String[] a){String s="";int i=0;for(String t:a){try{i+=Integer.parseInt(t);}catch(Exception e){s=t+" "+s;}}s+=i;System.out.println(s);}}
--- End code ---

3298:
Okay, challenge accepted, I'm going to cut that one down.

--- Code: ---String[] a
--- End code ---
Drop the space, 1 byte saved.

--- Code: ---for(String t:a){...}
--- End code ---
Drop the curly braces, 2 more bytes down (I just saw that in my submission as well). Your other solution already has that.

--- Code: ---s+=i;System.out.println(s);
--- End code ---
Two things here: Drop the ln (like in your submission), 2 bytes saved. The concatenation of string and number can be done inside the parentheses of the print, saving 3 more bytes.
Total improvement: 8 bytes, so the size is 161 now. :thumbsup:

JWinslow23:
New contest is underway!

Please move any and all discussion on code golfing here.

I already have a solution in TI-BASIC that is 122 bytes large. Who can do better?

Juju:
Welp, I just learned I could cut out 4 bytes in my Ruby entry by shortening "print" with "p" o.o

Welp, now I know.

Navigation

[0] Message Index

[*] Previous page

Go to full version