DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

99 Bottles Of Beer

04.10.2012
| 4181 views |
  • submit to reddit
        def bottle(x)
  case x
  when 0 then "no more bottles"
  when 1 then "1 bottle"
  else        "#{x} bottles"
  end + " of beer"
end

99.downto(1) do |i|
  puts <<T
#{bottle(i)} on the wall, #{bottle(i)},
take one down, pass it around,
#{bottle(i - 1)} on the wall.\n
T
end