見出し画像

99 bottles of beer

#
# 99 bottles of beer
#
99.downto(0) do |k|
case k
when 0
before = "no more bottles"
after = "99 bottles"
when 1
before = "1 bottle"
after = "no more bottles"
else
before = "#{k} bottles"
after = "#{k-1} bottles"
end
if k == 0
action = "Go to the store and buy some more"
else
action = "Take one down and pass it around"
end
puts "#{before.capitalize} of beer on the wall,"
puts "#{before} of beer."
puts "#{action}, "
puts "#{after} of beer on the wall."
puts "" unless k == 0
end

この記事が気に入ったらサポートをしてみませんか?