Skip to content

Instantly share code, notes, and snippets.

@zloyrusskiy
Created February 1, 2019 17:49
Show Gist options
  • Save zloyrusskiy/db17ec8ad16e83f44a3ad6c4d4c191bf to your computer and use it in GitHub Desktop.
Save zloyrusskiy/db17ec8ad16e83f44a3ad6c4d4c191bf to your computer and use it in GitHub Desktop.
fizzbuzz enumerator
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