No such thing as a small change | |
PerlMonks |
Re^3: cannot follow hanoi subroutineby graq (Curate) |
on Nov 05, 2007 at 09:03 UTC ( [id://648974]=note: print w/replies, xml ) | Need Help?? |
First all, apologies for ruining some nice code. I have added a print statement and 4 comment points (A .. D).
The first hanoi call happens at point A, where the first argument (which disk to move) is equal the number of discs on pile A; namely '3'. We then move into the hanoi iterative method where the logical statement at B is false and we move to point C. At point C we call hanoi again (note we have not called report yet, but the first argument has been decremented to '2'. This means we arrive at point B for the second time and the logical statement is still false. We arrive at point C again, calling hanoi on disk number 1. Now the statement at B is true and the iterations begin to unravel. Perhaps, together with the additional print statement in the code, this will help to explain things? -=( Graq )=-
In Section
Seekers of Perl Wisdom
|
|