Last active
April 24, 2016 14:00
-
-
Save GeorgeTaveras1231/8361434a488187862e7e6d3c7dcaa9fd to your computer and use it in GitHub Desktop.
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
module Fibonacci | |
module_function | |
def fibonacci(n) | |
@cache ||= {} | |
@cache[n] ||= if n <= 1 | |
n | |
else | |
fibonacci(n - 1) + fibonacci(n - 2) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment