From: Tom Gilbert Date: 2001-07-19T08:15:42+09:00 Subject: [ruby-talk:18076] Re: 99 bottles of beer * Dat Nguyen (thucdat@hotmail.com) wrote: > # How to shorten the following experimental codes? > > bottle = ' bottles' > 99.downto(1) { |i| > print "\n", i, bottle, ' of beer on the wall, ', i, bottle, ' of beer', ".\ > n" > print 'Take one down, pass it around,', "\n" > bottle = ' bottle' if i == 2 > print i-1, bottle, ' of beer on the wall.', "\n" if i > 1 > } > print 'No bottles of beer on the wall.', "\n\n" 99.downto(1) { |i| print <1} of beer on the wall, \ #{i} bottle#{'s' if i>1} of beer Take one down, pass it around, #{i==1 ? 'No' : i-1} bottle#{'s' if i!=2} of beer on the wall.\n BEER } Tom. -- .^. .-------------------------------------------------------. /V\ | Tom Gilbert, London, England | http://linuxbrit.co.uk | /( )\ | Open Source/UNIX consultant | tom@linuxbrit.co.uk | ^^-^^ `-------------------------------------------------------'