Hacker News new | ask | show | jobs
by devoutsalsa 1034 days ago
I just did it for fun. This particular recursive approach is super slow for numbers of nontrivial size, so I was just curious if I could even make the caching work in the block. It's not worth optimizing a suboptimal query when a more efficient option is available anyway.
1 comments

You don't need the `unless k.key? v` guard. The `Hash.new` block only gets called when the key is not present in the hash.
The caching makes it faster the trade off being more using more memory. I just wanted to see if it’d work.