Created
June 21, 2016 02:14
-
-
Save rosslebeau/d7da66c56e88dc3de3ce0440c766375c to your computer and use it in GitHub Desktop.
Companion gist for http://rosslebeau.com/2016/fizzbuzz-challenge-ruby-thinking-functionally
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
def fizzbuzz start, limit | |
(start..limit).to_a.map { |n| | |
printFizzBuzzForInput n | |
} | |
end | |
def printFizzBuzzForInput n | |
print "#{'fizz' * f(n)}" | |
print "#{'buzz' * g(n)}" | |
print "#{n.to_s * h(n)}" | |
print "\n" | |
end | |
def f n | |
((n % 3 / (n % 3 + 1.0)).ceil - 1) * (-1) | |
end | |
def g n | |
((n % 5 / (n % 5 + 1.0)).ceil - 1) * (-1) | |
end | |
def h n | |
(n % 3 / (n % 3 + 1.0)).ceil * (n % 5 / (n % 5 + 1.0)).ceil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment