Ruby let’s you form Hashes that makes it easier to work with Sequences using memoization. The computations are fast since it’s very much like a function but Memoized inside a hash collection.
Having the sequence available inside a Hash collection gives you more flexibility on how you can work with the sequence. Here’s a quick example to demonstrate this:
Since, everyone does Fibonacci Sequence, We’ll be looking at Triangular Numbers Sequence here: