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:
Man of Honour
Joined
29 Jun 2004
Posts
21,560
Location
Oxfordshire
rofl, first effort in C++, 49kb :D :p

I'm not going to go into Assembly either to condense it

The exe is 49kb anyway, the actual code is 40bytes, so I'll claim that one :p
 
Soldato
Joined
18 Oct 2002
Posts
5,464
Location
London Town
189 bytes with PHP is my effort :D. Nasty:
PHP:
<?$a='bottles of beer';for($i=99;$i>0;$i--){echo"$i $a, $i $a on the wall.\n";echo($i>1)?'Take one down and pass it around, '.($i-1):'Go to the store and buy some more, 99';echo" $a.\n\n";}
/edit- not quite, missed the singular bottle last line...
Okay, 261 then...
PHP:
<?for($i=99;$i>0;$i--){$b='bottle';$c=' of beer';$d='on the wall';$a=$b.(($i>1)?'s':'').$c;echo"$i $a $d, $i $a.\n";echo($i>1)?'Take one down and pass it around, '.($i-1)." $b":"Go to the store and buy some more, 99 {$b}s";echo((($i-1)>1)?'s':'')."$c $d.\n\n";}
 
Last edited:
Soldato
Joined
18 Oct 2002
Posts
3,157
Location
Leeds
Here's mine in PHP, 191 bytes but works perfectly :)

Code:
<?$a='bottles of beer';$b="$a on the wall";$i=99;while($i>0){echo"$i $b, $i $a.\n";echo($i-->1)?"Take one down and pass it around, $i":'Go to the store and buy some more, 99';echo" $b.\n\n";}


Mick.

/edit: doh! missed the singular
 
Last edited:
Soldato
Joined
18 Oct 2002
Posts
5,464
Location
London Town
Mickey said:
Here's mine in PHP, 191 bytes but works perfectly :)
Note the singular/plural of bottle in the last two lines:
2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
;)
 
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
Joined
18 Oct 2002
Posts
3,157
Location
Leeds
Can't get mine below 253 now in PHP :( damn single bottles!!!! ;)

Code:
<?$a='bottle';$b='of beer';$c="on the wall";$i=99;while($i>0){$d=$a.($i>1?'s ':' ').$b;echo"$i $d $c, $i $d.\n";echo($i-->1)?"Take one down and pass it around, $i":'Go to the store and buy some more, 99';$d=$a.($i!=1?'s ':' ').$b;echo" $d $c.\n\n";}

/edit: 249
 
Last edited:
Soldato
Joined
18 Oct 2003
Posts
3,667
Steedie said:
rofl, first effort in C++, 49kb :D :p

I'm not going to go into Assembly either to condense it

The exe is 49kb anyway, the actual code is 40bytes, so I'll claim that one :p

Erm you mean the code is 40kb?

The below is 39b and it doesn't do anything..
Code:
#include <iostream>
int main ()
{	
}
 
Last edited:
Soldato
Joined
18 Oct 2002
Posts
3,157
Location
Leeds
Right, 235 after some fiddling with mine :(
Code:
<?$a=' bottle%s of beer';$b=" on the wall";$i=99;while($i>0){$s=$i!=1?'s':'';printf("$i$a$b, $i$a.\n",$s,$s);echo($i-->1)?"Take one down and pass it around, $i":'Go to the store and buy some more, 99';printf("$a$b.\n\n",$i!=1?'s':'');}

232 after some fiddling with rob's
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?99:$j,$j==1?'':'s');}
 
Last edited:
Back
Top Bottom