From: Will Sobel Date: 2001-07-21T10:00:16+09:00 Subject: [ruby-talk:18216] Re: 99 bottles of beer Here's another variant without the warnings weighing in at 160 bytes. The |$n| in the proc is something I didn't expect to work, but did... - Will def b "#{$n>0?$n: 'No more'} bottle#{'s'if $n!=1} of beer"end 99.downto(1){|$n|w=" on the wall";puts b+w,b,"Take one down, pass it around ";$n-=1;puts b+w+'.'} -----Original Message----- From: Will Sobel [mailto:will.sobel@barra.com] Sent: Friday, July 20, 2001 5:49 PM To: ruby-talk@ruby-lang.org Subject: [ruby-talk:18215] Re: 99 bottles of beer def b "#{N>0?N: 'No more'} bottle#{'s'if N!=1} of beer"end (N=99).times{w=" on the wall";puts b+w,b,"Take one down, pass it around ";N-=1;puts b+w+'.'} Just knocked it down to 152. Output is kind of ugly, bit it works (complete with warnings!) - Will -----Original Message----- From: Kero van Gelder [mailto:kero@d4050.upc-d.chello.nl] Sent: Friday, July 20, 2001 5:42 PM To: ruby-talk@ruby-lang.org Subject: [ruby-talk:18213] Re: 99 bottles of beer > Here's an incremental squeezing of an earlier solution, I think by Steven > Grady, down to 164 (or has someone already done that?): > > def b(n)"#{n>0?n: 'No more'} bottle#{'s'if n!=1} of beer"end > 99.downto(1){|n|w=" on the wall";puts "#{b(n)+w}, #{b n}\nTake one down, pass it around\n#{b(n-1)+w}."} [165, by my count?] Not entirely; the original poster asked for a comma after ``around'' and an empty line in between the iterations. That costs you 5 bytes (a double '\n' in a puts). But, in the same way, ``more'' is not required, which saves you 5 bytes. You've got to be careful with these things :) NB: def b(n)"#{n>0?n: 'No'} bottle#{'s'if n!=1} of beer"end 99.downto(1){|n|w=" on the wall";puts b(n)+w+", #{b n}\nTake one down, pass it around,\n#{b(n-1)+w}.\n\n"} Is only 163 bytes. +--- Kero ------------------------------ kero@chello.nl ---+ | Don't split your mentality without thinking twice | | Proud like a God -- Guano Apes | +--- M38c ------- http://members.chello.nl/~k.vangelder ---+