Skip to content

Instantly share code, notes, and snippets.

@ricsdeol
Created September 29, 2015 04: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 ricsdeol/62e578a06c3963bf4bcc to your computer and use it in GitHub Desktop.
Save ricsdeol/62e578a06c3963bf4bcc to your computer and use it in GitHub Desktop.
Ruby Fibonnacci Memoization
2.1.6 :001 > fib = Hash.new{ |h,k| h[k] = k < 2 ? k : h[k-1]+h[k-2] }
=> {}
2.1.6 :002 > fib[1]
=> 1
2.1.6 :003 > fib[10]
=> 55
2.1.6 :004 > fib
=> {1=>1, 0=>0, 2=>1, 3=>2, 4=>3, 5=>5, 6=>8, 7=>13, 8=>21, 9=>34, 10=>55}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment