Created
June 15, 2015 20:19
-
-
Save ajbeach2/ce3be841df6aee8e01a6 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_fast(x , storage) | |
result = 0 | |
if x == 0 | |
result = 0 | |
elsif x == 1 | |
result = 1 | |
else | |
if storage[x] | |
result = storage[x] | |
else | |
result = fib_fast(x - 1, storage) + fib_fast(x - 2, storage) | |
end | |
end | |
storage[x] = result | |
return result | |
end | |
a = [] | |
10.times do |x| | |
puts fib_fast(x,a) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment