Created
August 12, 2016 18:15
-
-
Save esparkman/57be26d832a7083a6b234592e7f60a12 to your computer and use it in GitHub Desktop.
Fibonacci with Recursion
This file contains hidden or 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
@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