Skip to content

Instantly share code, notes, and snippets.

@ajbeach2
Created June 15, 2015 20:19
Show Gist options
  • Save ajbeach2/ce3be841df6aee8e01a6 to your computer and use it in GitHub Desktop.
Save ajbeach2/ce3be841df6aee8e01a6 to your computer and use it in GitHub Desktop.
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