Skip to content

Instantly share code, notes, and snippets.

@jasdeepsingh
Created May 9, 2013 22:28
Show Gist options
  • Save jasdeepsingh/5551099 to your computer and use it in GitHub Desktop.
Save jasdeepsingh/5551099 to your computer and use it in GitHub Desktop.
memoization inside hashes
>> tri = Hash.new { |hash,n| hash[n] = (n*(n+1))/2 }
{}
>> tri[1] = 1 # Setup the base case
1
>> tri[4]
10
>> tri[433]
93961
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment