Created
February 1, 2019 17:49
-
-
Save zloyrusskiy/db17ec8ad16e83f44a3ad6c4d4c191bf to your computer and use it in GitHub Desktop.
fizzbuzz enumerator
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
fizzbuzz = Enumerator.new do |y| | |
num = 0 | |
loop do | |
y << case | |
when num % 15 == 0 then "FizzBuzz" | |
when num % 3 == 0 then "Fizz" | |
when num % 5 == 0 then "Buzz" | |
else num | |
end | |
num += 1 | |
end | |
end | |
pp fizzbuzz.take(20) | |
=begin | |
["FizzBuzz", | |
1, | |
2, | |
"Fizz", | |
4, | |
"Buzz", | |
"Fizz", | |
7, | |
8, | |
"Fizz", | |
"Buzz", | |
11, | |
"Fizz", | |
13, | |
14, | |
"FizzBuzz", | |
16, | |
17, | |
"Fizz", | |
19] | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment