Skip to content

Instantly share code, notes, and snippets.

@tedi
Created August 5, 2014 20:40
Show Gist options
  • Save tedi/d21adfe2428adb19263d to your computer and use it in GitHub Desktop.
Save tedi/d21adfe2428adb19263d to your computer and use it in GitHub Desktop.
# BEWD2 optimized solution for 99 bottles
def pluralize(word, count)
"#{count} #{word}#{'s' unless count == 1}"
end
def sing_bottles(count)
pluralized_count = pluralize("bottle", count)
puts "#{pluralized_count} of beer on the wall"
puts "#{pluralized_count} of beer"
puts "#{pluralize("bottle", count - 1)} of beer on the wall!"
puts "You take one down and pass it around," unless count == 1
end
99.downto(2) do |count|
sing_bottles(count)
puts "#{bottle_count(count - 1)} of beer on the wall!"
end
sing_bottles(1)
puts "No more bottles of beer on the wall :-("
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment