Skip to content

Instantly share code, notes, and snippets.

@ahlusar1989
Forked from tedi/99 bottles
Created August 5, 2014 22:13
Show Gist options
  • Save ahlusar1989/4798f50322105a020549 to your computer and use it in GitHub Desktop.
Save ahlusar1989/4798f50322105a020549 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