mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-26 21:58:56 +01:00
8 lines
No EOL
259 B
Ruby
8 lines
No EOL
259 B
Ruby
# Given a number, calculates the nth fibonacci number.
|
|
|
|
def fast_fibonacci(number, memo_hash = {})
|
|
if number == 0 || number == 1
|
|
return number
|
|
end
|
|
memo_hash[number] ||= fibonacci(number - 1, memo_hash) + fibonacci(number -2, memo_hash)
|
|
end |