In this exercise you're going to be using a concept called dynamic programming. https://en.wikipedia.org/wiki/Dynamic_programming
Your solution could use the class method #define_singleton_method
or the combination of #method_missing
and #respond_to_missing
.