Comments

Yeah men, keep doing the good work. How Deep is this men, it moves me to tears.

rafa said on 01/25/07 18:49:34

I really like this over the other versions, I think it shows more the ruby way.

The part I liked the more was the last line, especially "}.sing {", that makes use of a not commonly known behavior of ruby continuations. When the continuation is called the first time, the #sing message is sent to the value resulting from the body of callcc, however subsequent calls to the continuation (by means of wall.call) always send the #sing message to the nil object. I proved this by changing "song = nil" to "song = Object.new", now I understand why Victor used nil as the song, a very cleaver choice !.

Hesenrre said on 01/26/07 02:05:15

Jejejejeje, like your coding friend :D, ruby rules!!!!

Namagem said on 12/31/08 16:33:56

It's absolutely possible to make a slightly less polished version in only 4 lines.
I actually think I'll submit it.

similar to python one said on 02/19/09 16:23:05

A friend said the python version looked cleaner. So I wrote that one in Ruby.

(1..99).to_a.reverse.each do |bottle|
if bottle > 1
puts "#{bottle} bottles of beer on the wall, #{bottle} bottles of beer."
suffix = bottle > 2 ? "#{bottle -1} bottles of beer on the wall" : "1 bottle of beer on the wall"
elsif bottle == 1
puts "1 bottle of beer on the wall, 1 bottle of beer."
suffix = "no more beer on the wall!"
end

puts "Take one down, pass it around #{suffix}"
puts "--"
end

jeff said on 03/24/09 05:53:56

As noted by the first comment, this entry stands out not for being the shortest, but because it shows some neat language features, and how they are combined in the last line, that looks almost like a DSL. I think many rubyists would agree, in that ruby makes programming so easy, that the focus is more in expression and artistic value.

Nice codes.

Billy said on 12/16/09 02:33:42

I really like this one!

num_bot = proc { |n| "#{n} bottle#{n == 1 ? '' : 's'}" }

99.downto(2) do |num|
puts "#{num_bot[num]} of beer on the wall, #{num_bot[num]} of beer!"
puts "Take one down, pass it around, #{num_bot[num-1]} of beer on the wall!"
end

puts "#{num_bot[1]} of beer on the wall, #{num_bot[1]} of beer!"
puts "Take one down, pass it around, no more bottles of beer on the wall!"