Skip to content

Instantly share code, notes, and snippets.

@esparkman
Created August 12, 2016 18:15
Show Gist options
  • Save esparkman/57be26d832a7083a6b234592e7f60a12 to your computer and use it in GitHub Desktop.
Save esparkman/57be26d832a7083a6b234592e7f60a12 to your computer and use it in GitHub Desktop.
Fibonacci with Recursion
@cache = [0,1]
def fib(number)
return @cache[number] if @cache[number]
@cache[number] = fib(number-1) + fib(number-2)
end
(1..50).each { |n| puts fib(n) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment