|laziness, impatience, and hubris|
Re: Recursion Confusionby BrowserUk (Pope)
|on Apr 27, 2013 at 07:36 UTC||Need Help??|
A step-by-step explanation is what I am looking for.
Okay. (but you could have produced this yourself; see Devel::Trace):
But, whilst that may help you wrap your head around an existing recursive implementation, it probably won't help you with writing your own recursive routines.
The trick to understanding and using recursion is to avoiding trying to 'run the loops' in your head, and instead think about the subroutine in snapshots. That is to say, imagine each of the situations (states) that could exist at the point of entry to the subroutine and then what needs to be done to move that state to the next state.
So for the routine above the are two states:
For three discs, we only need to do: the above two disc procedure but from $start to $extra; followed by the one disc procedure from $start to $end; followed by the two disc procedure from $extra to $end.
And by now, you should be able to see that by passing in $n == 3, that is exactly what happens.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.