Forum: Ruby FizzBuzz (#126) [SOLUTION]

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8100138c6c0cd6f3bc27b4fe55c550e5?d=identicon&s=25 doug meyer (Guest)
on 2007-06-03 19: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'
  else
    puts number
  end
end

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.