Skip to content

Instantly share code, notes, and snippets.

@kano4
Created October 15, 2011 09:10
Show Gist options
  • Save kano4/1289311 to your computer and use it in GitHub Desktop.
Save kano4/1289311 to your computer and use it in GitHub Desktop.
FibBuzz in Ruby
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