Created
April 18, 2015 14:00
-
-
Save l3kn/8dab6156c5ebe5c63bd0 to your computer and use it in GitHub Desktop.
Lazy FizzBuzz
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 = ["","","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