Forum: Ruby FizzBuzz (#126) [SOLUTION]

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
doug meyer (Guest)
on 2007-06-03 21:32
(Received via mailing list)
This is one of those quizzes that is so easy, you have to find some
ridiculous way of solving it :-D

First off, there is the correct way of coding: clear, concise, and
actually works

#!/usr/bin/env ruby
# Douglas Meyer

(1..100).each do |number|
  if number % 3 == 0 && number % 5 == 0
    puts 'FizzBuzz'
  elsif number % 3 == 0
    puts 'Fizz'
  elsif number % 5 == 0
    puts 'Buzz'
    puts number

Then there is the solution I would NEVER give during an interview or
use in a application (unless I had tests, and I was the only one
programming the application). I think this is the first time I used
zip, also the |x,*y| makes me think of erlang, lol

#!/usr/bin/env ruby
# Douglas Meyer

(1..100).zip((([nil]*2<<'Fizz')*34),([nil]*4<<'Buzz')*20){|x,*y| puts
(y.compact.empty? ? x : y.join())}
This topic is locked and can not be replied to.