Created
June 13, 2015 03:41
-
-
Save ajbeach2/3c0192e1e50b24268bca 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
def fib(x, sequence = []) | |
if x <= 1 | |
result = 1 | |
elsif | |
result1 = sequence[x - 1] ||= fib(x - 1) | |
result2 = sequence[x - 2] ||= fib(x - 2) | |
result = result1 + result2 | |
end | |
sequence[x] = result | |
return result | |
end | |
a = [] | |
fib(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment