feat: added fibonacci.rb

This commit is contained in:
范淼 2021-03-07 19:41:59 +08:00
parent 2e986753cd
commit 147ad062c6

View file

@ -0,0 +1,8 @@
# Given a number, calculates the fibonacci number.
def 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