Skip to content

Instantly share code, notes, and snippets.

@shuklaneerajdev
Created January 18, 2021 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuklaneerajdev/9c0cf44e1ccb729a36b9b307ccd62ffe to your computer and use it in GitHub Desktop.
Save shuklaneerajdev/9c0cf44e1ccb729a36b9b307ccd62ffe to your computer and use it in GitHub Desktop.
$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