-
-
Save mrb/3230825 to your computer and use it in GitHub Desktop.
Writing FizzBuzz without modulus division
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fizz = [nil, nil, "Fizz"].cycle.take(100) | |
buzz = [nil, nil, nil, nil, "Buzz"].cycle.take(100) | |
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