[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fwd: An obscure form of alcoholism]

I know that, at this point, the topic has little to do with the serious 
of lightweight languages, but I thought you folks might be interested to 
just how obsessive some of my pals have become about this "bottles of
beer" issue and the fun question of "how small can it be""

--- Dan

From: Oliver Xymoron 
To: Oliver Schade 
Cc: autarch@urth.org
Subject: Re: Minimal python version

On Sat, Oct 19, 2002 at 09:28:25PM +0200, Oliver Schade wrote:
> Hi Oliver.
> On Wed, 2002-10-02 at 09:55, Oliver Xymoron wrote:
> > a,t="\n%s bottles of beer on the wall","\nTake one down, pass it around"
> > for d in range(99,0,-1):print(a%d*2)[:-12]+t+a%(d-1 or'No')
> Added today. Many thanks,

Dave Rolsky and I played a couple rounds of golf on this one, with
Jamie McCarthy proferring a 131 char Perl version. This Python version
is 128 characters, not counting the final line break:

a="\n%s bottles of beer on the wall"
for d in range(99,0,-1):print(a%d*2)[:-12]+"\nTake one down, pass it around"+a%\(d-1 or'No')

After a bit of thought, I came up with a Perl 1-liner version
significantly better than those offered by the self-professed Perl
hackers, and sadly, my lovely Python version:

for($c=99;$c;printf"$c$b$c%.16s\ntake one down, pass it around\n%s$b\n",$b,--$c||No){$b=" bottles of beer on the wall\n"}

This version will be rather tough to beat, weighing in at a mere 121
characters and having a bare minimum of punctuation. But wait! A
couple more tricks up my Python sleeve brings Python back in the lead
at 119:

a,d="bottles of beer on the wall\n",99
while d:print d,a,d,a[:15],"\nTake one down, pass it around\n",d-1 or'No',a;d-=1

While I'm at it, here's a minimal C version (139 characters):

main(c){char*b=" bottles of beer on the wall\n";for(c=100;--c;)printf("%d%s%d%.16s\ntake one down, pass it around\n%d%s\n",c,b,c,b,c-1,b);}

And here's an even shorter Python version that cheats slightly:

import urllib;print urllib.urlopen("http://waste.org/beer";).read()

Perhaps the saddest part of this is: I don't drink.

 "Love the dolphins," she advised him. "Write by W.A.S.T.E.."