Created
October 15, 2011 09:10
-
-
Save kano4/1289311 to your computer and use it in GitHub Desktop.
FibBuzz in Ruby
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 fibbuzz(to) | |
fib = [0, 1] | |
fib << fib[-1] + fib[-2] while fib.last < to | |
result = [] | |
1.upto(to) do |x| | |
output = x | |
output = 'Fib' if fib.include?(x) | |
output = 'Buzz' if x % 5 == 0 | |
output = 'FibBuzz' if fib.include?(x) && x % 5 == 0 | |
result << output | |
end | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment