-
-
Save ahlusar1989/4798f50322105a020549 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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