Hacking, Coding and Gaming | @[email protected]

I recently heard about the "Fizz Buzz Test", a kind of programming "interview" question or challenge. In short, a given number needs to be checked if it's divisible by 3 or 5 (or 3 and 5) and output either "Fizz", "Buzz" or "Fizz Buzz" accordingly

There's a great explanation about the problem, and why it's not as simple as it seems, at http://c2.com/cgi/wiki?FizzBuzzTest

Here's my go at it:


def fizzbuzz(num)
  fizz = (num % 3 == 0) ? "Fizz" : ""
  buzz = (num % 5 == 0) ? "Buzz" : ""
  (fizz.empty? && buzz.empty?) ? num.to_s : fizz+buzz
end

(1..100).each {|num| puts fizzbuzz(num)}

Simple, and easy enough to read, me thinks :) Any thoughts?