Skip to content

Instantly share code, notes, and snippets.

@l3kn
Created April 18, 2015 14:00
Show Gist options
  • Save l3kn/8dab6156c5ebe5c63bd0 to your computer and use it in GitHub Desktop.
Save l3kn/8dab6156c5ebe5c63bd0 to your computer and use it in GitHub Desktop.
Lazy FizzBuzz
fizz = ["","","Fizz"].lazy.cycle
buzz = ["","","","","Buzz"].lazy.cycle
numbers = (1..Float::INFINITY).lazy
fizzbuzz = numbers.zip(fizz,buzz).map do |n,f,b|
(f.empty? && b.empty?) ? n.to_s : f + b
end
puts fizzbuzz.take(20).to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment