Skip to content

Instantly share code, notes, and snippets.

@GeorgeTaveras1231
Last active April 24, 2016 14:00
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 GeorgeTaveras1231/8361434a488187862e7e6d3c7dcaa9fd to your computer and use it in GitHub Desktop.
Save GeorgeTaveras1231/8361434a488187862e7e6d3c7dcaa9fd to your computer and use it in GitHub Desktop.
module Fibonacci
module_function
def fibonacci(n)
@cache ||= {}
@cache[n] ||= if n <= 1
n
else
fibonacci(n - 1) + fibonacci(n - 2)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment