2009-08-23, 01:56 PM
Instead of recursion, you could use an array to store the answers from each step and then generate the next step from that (there's a term for this but I forget). You have to generate every single answer, rather than just the few you need, but you only need to calculate each answer once instead of recursing forever.
Disclaimer: I haven't tried this so I don't know if it's actually an improvement.
Disclaimer: I haven't tried this so I don't know if it's actually an improvement.

