Skip to content

Instantly share code, notes, and snippets.

@hrstt
Created March 22, 2012 07:17
Show Gist options
  • Select an option

  • Save hrstt/2156816 to your computer and use it in GitHub Desktop.

Select an option

Save hrstt/2156816 to your computer and use it in GitHub Desktop.
hash memorize
# 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