Created
March 22, 2012 07:17
-
-
Save hrstt/2156816 to your computer and use it in GitHub Desktop.
hash memorize
This file contains hidden or 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
| # recursive call with hash | |
| # calcuation procedure define in block of constractor. | |
| # this hash return response first, but its key size is limited about 1,000 keys | |
| # => occur SystemStackError | |
| h = Hash.new{|hash, value| hash[value] = 1 + hash[value -1] + hash[value -2]} | |
| h[0] = 1 | |
| h[1] = 1 | |
| puts h[3] #=> 5 | |
| puts h[100] #=> 1146295688027634168201 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment