From: David Alan Black Date: 2001-07-19T20:58:44+09:00 Subject: [ruby-talk:18111] Re: 99 bottles of beer Hello -- On Thu, 19 Jul 2001, Steven Grady wrote: > (I believe in Perl circles this is called Golf. This is the first > thread I've seen of Ruby Golf..) I wonder what gem cutters call it when they achieve their goal using the fewest strokes.... > 174 bytes: > > def b(n) "#{n>0?n: 'No more'} bottle#{n!=1?'s': ''} 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}."} Not that you should listen to me (my attempt weighed in > 210), but you can trim a few bytes: 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)+". Take one down, pass it around,\n"+b(n-1)+w+"."} (I've also tweaked the punctuation a bit.) I'd love to get rid of the last remaining ternary operator, but the shortest substitute I can come up with (n>0&&n||'No more') is one byte longer. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav