Created
January 18, 2021 05:01
-
-
Save shuklaneerajdev/9c0cf44e1ccb729a36b9b307ccd62ffe 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
$map = Hash.new | |
def fibonacci(n) | |
if $map.key?(n) | |
return $map[n] | |
end | |
if n==1 || n==0 | |
return 1 | |
else | |
val = fibonacci(n-1)+fibonacci(n-2) | |
$map[n] = val | |
return val | |
end | |
end | |
puts fibonacci(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment