Skip to content

Instantly share code, notes, and snippets.

@JEG2
Created August 1, 2012 21:07
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JEG2/3230760 to your computer and use it in GitHub Desktop.
Save JEG2/3230760 to your computer and use it in GitHub Desktop.
Writing FizzBuzz without modulus division
fizz = [nil, nil, "Fizz"].cycle
buzz = [nil, nil, nil, nil, "Buzz"].cycle
numbers = 1..100
numbers.zip(fizz, buzz) do |n, f, b|
fizzbuzz = [f, b].join
puts(fizzbuzz.empty? ? n : fizzbuzz)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment