hrstt
3/22/2012 - 7:17 AM

hash memorize

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