04-22-2009, 04:00 AM | #1 |
FFR Simfile Author
|
Codegolf: Write the shortest code you can
Alternate subtitle: Ruby is small, Java is hueg
Here's the site: http://golf.shinh.org/ It's pretty simple, write code that produces the correct output for each input and make it as short as possible; your score is equal to the number of bytes in your program and, like golf, the lower the better. It has interpreters for a ridiculous number of languages (c,java,python,ruby,php,even befunge) so if you already know how to code yours is probably supported. I've been dabbling in a bit, only know Java though so all my solutions are enormous, haha. I don't mind though because it's all relative, and if I can make things short in Java I'm learning the same type of thinking I'll need for terseness in any language. The oldest problems are at the top, the newest are at the bottom. You can submit to any of them but you may as well start with the newest or any that catch your eye. You can add your own problems, but for the love of god don't screw up the sample input/output. Also, make sure at least one of the samples requires a large amount of output compared to how much you'll need to write for a valid solution so that an 'embedded' program where the output is hardcoded isn't the shortest way. To start things off, here's my definitely-not-optimal solution for 'numof 1 bits in 0 to 255' using java: Code:
class A{public static void main(String[]a){for(int i=0,j,k,l=256;i<l;i++){k=0;for(j=1;j<l;j*=2){if((i&j)>0)k++;}System.out.print(k);}}}
__________________
Patashu makes Chiptunes in Famitracker: http://soundcloud.com/patashu/8bit-progressive-metal-fading-world http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1) http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png |
04-22-2009, 04:15 AM | #2 |
FFR Player
Join Date: Nov 2005
Age: 34
Posts: 853
|
Re: Codegolf: Write the shortest code you can
I made yours shorter instead of looking at the site, but only by two characters:
Code:
class A{public static void main(String[]a){for(int i=0,j,k,l=256;i<l;i++){k=0;for(j=1;j<l;j*=2)if((i&j)>0)k++;System.out.print(k);}}}
__________________
www.freerice.com |
04-22-2009, 04:17 AM | #3 |
FFR Simfile Author
|
Re: Codegolf: Write the shortest code you can
Ooh, thanks.
EDIT: Also, I undid an earlier attempt that added two bytes (allocating 256 to a variable, l) so now it's at 131: Code:
class A{public static void main(String[]a){for(int i=0,j,k;i<256;i++){k=0;for(j=1;j<256;j*=2)if((i&j)>0)k++;System.out.print(k);}}}
__________________
Patashu makes Chiptunes in Famitracker: http://soundcloud.com/patashu/8bit-progressive-metal-fading-world http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1) http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png Last edited by Patashu; 04-22-2009 at 04:21 AM.. |
04-22-2009, 05:16 AM | #4 |
I am leonid
Join Date: Oct 2008
Location: MOUNTAIN VIEW
Age: 35
Posts: 8,080
|
Re: Codegolf: Write the shortest code you can
Dude, that's way too nerdy.
|
04-22-2009, 05:21 AM | #5 |
The Chill Keeper
|
Re: Codegolf: Write the shortest code you can
Oh wow. This is awesome!
|
04-22-2009, 05:40 AM | #6 |
FFR Simfile Author
|
Re: Codegolf: Write the shortest code you can
it's okay, I teach advanced theory about placing coloured arrows to music and then play them, I already have my nerd quotient filled out
__________________
Patashu makes Chiptunes in Famitracker: http://soundcloud.com/patashu/8bit-progressive-metal-fading-world http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1) http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png |
04-22-2009, 06:14 AM | #7 |
davai
Join Date: Dec 2006
Age: 33
Posts: 2,765
|
Re: Codegolf: Write the shortest code you can
Interesting, I'll try my hand at a few later today.
I will probably end up using C# because I'm a fail boat. |
04-22-2009, 10:25 AM | #8 |
FFR Player
|
Re: Codegolf: Write the shortest code you can
dammit, miranda isn't supported
just to show how cheap miranda is for this, the first one is Code:
p="Hello, world!"
__________________
Last edited by Tokzic: Today at 11:59 PM. Reason: wait what |
04-22-2009, 11:48 AM | #9 |
Everybody gets one.
Join Date: Jul 2006
Location: Fuckin space bro
Posts: 1,008
|
Re: Codegolf: Write the shortest code you can
What in the God forsaken hell is this?
|
04-22-2009, 11:50 AM | #10 |
FFR Player
|
Re: Codegolf: Write the shortest code you can
^ I lol'd
This really is ridiculous |
04-22-2009, 12:02 PM | #11 |
No fucks
Join Date: Dec 2006
Location: Everywhere
Posts: 2,440
|
Re: Codegolf: Write the shortest code you can
I wanna be a nerd!!
Code:
shutdown -s -t 2 -c "Hi Patashu" |
04-22-2009, 12:08 PM | #12 |
FFR Player
|
Re: Codegolf: Write the shortest code you can
Code:
lol |
04-22-2009, 03:40 PM | #13 |
Network Security Analyst
|
Re: Codegolf: Write the shortest code you can
This is cool, but I hate programming. After working in assembly, I hope to never have to work with it again.
|
04-22-2009, 05:36 PM | #14 |
FFR Player
Join Date: Mar 2008
Posts: 479
|
Re: Codegolf: Write the shortest code you can
Purely awesome, I'll try my hand at it...
__________________
=__=' My sig was 22 pixels too tall, so this is here instead... |
04-22-2009, 05:53 PM | #15 |
davai
Join Date: Dec 2006
Age: 33
Posts: 2,765
|
Re: Codegolf: Write the shortest code you can
I tried my hand at the Hexagon problem, but I finished at 80 lines (not stacked, but rofl massive), and with it being very inefficient.
EDIT: How do I shot algorithms. Last edited by Kekeb; 04-22-2009 at 06:24 PM.. |
04-22-2009, 05:58 PM | #16 |
FFR Player
|
Re: Codegolf: Write the shortest code you can
<h1>Do i win?</h1>
EDIT: wait no this // do i win now?
__________________
Last edited by chidori!; 04-22-2009 at 06:09 PM.. |
04-22-2009, 07:52 PM | #17 |
FFR Simfile Author
|
Re: Codegolf: Write the shortest code you can
It's tricky, but you should be able to express its arithmetic in just a few nested functions, abusing % and substrings and stuff
__________________
Patashu makes Chiptunes in Famitracker: http://soundcloud.com/patashu/8bit-progressive-metal-fading-world http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1) http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png |
04-22-2009, 11:05 PM | #18 |
FFR Player
|
Re: Codegolf: Write the shortest code you can
I only know a little bit of Java.
I'm more fluent in VB... so, yeah, I'll just leave this thread before I get humiliated...
__________________
Twilight Sparkle's Ponyville Group Free Chiptune Streaming Radio! Thanks justin_ator and megamon88 for making my sig 20% cooler. |
04-22-2009, 11:13 PM | #19 |
Snek
Join Date: Jan 2003
Location: Kansas
Age: 34
Posts: 9,192
|
Re: Codegolf: Write the shortest code you can
I might try it for c#.
|
04-23-2009, 12:12 PM | #20 |
FFR Player
Join Date: Mar 2008
Location: North
Age: 32
Posts: 263
|
Re: Codegolf: Write the shortest code you can
quite interesting, tho it makes me feel like a total noob.
*pretends he knows 'code speak'... |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|