Skip to content

Instantly share code, notes, and snippets.

@sorah
Created October 13, 2011 06:22
Show Gist options
  • Save sorah/1283547 to your computer and use it in GitHub Desktop.
Save sorah/1283547 to your computer and use it in GitHub Desktop.
def fibBuzz(n)
i = 0
fib0 = 1
fib1 = 1
puts "1"
puts "1"
while i < n
i+=1
fib2 = fib0+fib1
fib0 = fib1
fib1 = fib2
str = ""
if fib1 % 3 == 0
str += "Fizz"
end
if fib1 % 5 == 0
str += "Buzz"
end
if str.length == 0
str = fib2.to_s
end
puts str
end
end
fibBuzz(100)
def fibbuzz(n)
(1..100).inject([1,1]){|s| s<<s[-1]+s[-2] }.map{|i| i%15==0 ? "FizzBuzz" : i%3==0 ? "Fizz" : i%5==0 ? "Buzz" : i }
end
puts fibbuzz(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment