Last active
December 17, 2015 20:28
-
-
Save theleoborges/5667463 to your computer and use it in GitHub Desktop.
Functional Fizz Buzz in Ruby 2.0
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
threes = ["", "", "fizz"].cycle.lazy | |
fives = ["", "", "", "", "buzz"].cycle.lazy | |
(1..Float::INFINITY).lazy.zip(threes, fives).map{|n,f,b| | |
if f.empty? && b.empty? | |
return n | |
elsif f.empty? | |
return b | |
else | |
return [f,b].join | |
end | |
}.take(30).to_a | |
# [1, 2, "fizz", 4, "buzz", "fizz", 7, 8, "fizz", "buzz", 11, "fizz", 13, 14, "fizzbuzz", | |
# 16, 17, "fizz", 19, "buzz", "fizz", 22, 23, "fizz", "buzz", 26, "fizz", 28, 29, "fizzbuzz"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from fizzbuzz import *
nailed_it()