|laziness, impatience, and hubris|
Misunderstanding Recursionby Andrew_Levenson (Hermit)
|on Dec 15, 2006 at 21:44 UTC||Need Help??|
Andrew_Levenson has asked for the
wisdom of the Perl Monks concerning the following question:
Last night I happened upon DigitalKitty's Recursion: The Towers of Hanoi problem, which opened my eyes to the world of recursion (thanks for that, by the way). Never had the thought occurred to me that I could call a loop from within that loop. So I revisited my old prime script with this new tool in hand.
After toying with it a bit, I gave it a go. Extremely fast for up to 1000. Then it started to slow down, which puzzled me. When doing up to one million (not a problem for previous versions) it got hung up around 700,000.
Why, oh why, fellow monks, does this script
run so much slower than this script?
From my (severely limited) point of view, it should run a lot faster/be more efficient than the latter. Is there some feature of recursion that I don't know about that is causing me to choke?
Thanks in advanced!