Golf!

Soldato
Joined
26 Dec 2003
Posts
16,522
Location
London
I'm bored, so let's play golf.

Step 1: Make a program that produces this output (note how it changes for one bottle).

Step 2: Condense that program so it's as small as you can possibly get it while still working.

Step 3: Curse as some horrible person gets it down to 5 bytes somehow.

Any language, go go go!

I've got an embarrassing 245 bytes with PHP so far; let's see what you can do!
 
Last edited:
Soldato
OP
Joined
26 Dec 2003
Posts
16,522
Location
London
Here's my 245. I can't get it smaller than that :(

Code:
<? for($j=$i=99;$i>0;$i--){$f="%d bottle%s of beer";$g=" on the wall";printf("$f$g, $f.\n",$i,$s=$i==1?'':'s',$i,$s);printf((--$j>0?"Take one down and pass it around":"Go to the store and buy some more").", $f$g.\n\n",$j==0?99:$j,$j==1?'':'s');}
 
Soldato
OP
Joined
26 Dec 2003
Posts
16,522
Location
London
Actually, 243:

Code:
<? for($j=$i=99;$i>0;){$f="%d bottle%s of beer";$g=" on the wall";printf("$f$g, $f.\n",$i,$s=$i==1?'':'s',$i--,$s);printf((--$j>0?"Take one down and pass it around":"Go to the store and buy some more").", $f$g.\n\n",$j==0?99:$j,$j==1?'':'s');}
 
Soldato
OP
Joined
26 Dec 2003
Posts
16,522
Location
London
235:

Code:
<? for($j=$i=99;$i>0;){$f="%d bottle%s of beer";$g=" on the wall";printf("$f$g, $f.\n".(--$j>0?"Take one down and pass it around":"Go to the store and buy some more").", $f$g.\n\n",$i,$s=$i==1?'':'s',$i--,$s,$j==0?99:$j,$j==1?'':'s');}

Edit: I don't think it's getting any smaller than this :( I still don't see how people have got sub-200!
 
Last edited:
Soldato
OP
Joined
26 Dec 2003
Posts
16,522
Location
London
I suck far far too much at Ruby :(

Code:
99.downto(0){|i|j=(i==0)?"99":(i-1).to_s;i=i.to_s;s=(i==1)?"":"s";z=(j==1)?"":"s";puts i+" bottle"+s+" of beer on the wall, "+i+" bottle"+s+" of beer.\n"+(i=="0"?"Go to the store and buy some more":"Take one down and pass it around")+", "+j+" bottle"+z+" of beer on the wall.\n\n"}

(281 with loads of potential for reduction)
 
Soldato
OP
Joined
26 Dec 2003
Posts
16,522
Location
London
Can't you get it even smaller by using braces instead of end? Also doesn't it use the singular for 0 bottles too?

Nicely done though, I love Ruby for stuff like this :)
 
Soldato
OP
Joined
26 Dec 2003
Posts
16,522
Location
London
growse said:
Code:
$w=" on the wall";$i=99;print$i.&s."$w, $i".&s.". ".(--$i?"Take one down and pass it around, $i":'Go to the store and buy some more, 99').&s."$w."while$i;sub s{' bottle'.($i!=1?'s':'').' of beer'}

197. I (more like, this guy I know) wins!

Perl should be banned from Golf competitions :(
 
Back
Top Bottom