I know this thread is a bit old but,
"on - in this order). Then the body of the function might look like
Solve(N, Src, Aux, Dst)
if N is 0
exit
else
Solve(N-1, Src, Dst, Aux)
Move from Src to Dst
Solve(N-1, Aux, Src, Dst)
This actually serves as the definition of the function Solve. The function is recursive in that it calls itself repeatedly with decreasing values of N until a terminating condition (in our case N=0) has been met. To me the sheer simplicity of the solution is breathtaking. For N=3 it translates into
Move from Src to Dst
Move from Src to Aux
Move from Dst to Aux
Move from Src to Dst
Move from Aux to Src
Move from Aux to Dst
Move from Src to Dst
Of course "Move" means moving the topmost disk. For N=4 we get the following sequence
Move from Src to Aux
Move from Src to Dst
Move from Aux to Dst
Move from Src to Aux
Move from Dst to Src
Move from Dst to Aux
Move from Src to Aux
Move from Src to Dst
Move from Aux to Dst
Move from Aux to Src
Move from Dst to Src
Move from Aux to Dst
Move from Src to Aux
Move from Src to Dst
Move from Aux to Dst
"
http://www.cut-the-knot.org/recurrence/hanoi.shtml
Okay...I don't understand how when N=3 it outputs
Move from Src to Dst
and when N= 4 it outputs
Move from Src to Aux,
I understand that the solution requires that, but I don't understand how in the program changing N changes the first output. Why doesn't it always output "Move from Src to Dst"?
For n=2
it would be
Move Src to Aux.
Move Src to Dest.
Move Aux to Dest.
but I don't understand how that program would output that?? tHanks.
I DO Understand that
If the number of disks is EVEN, the first move is Src to Aux.
ELSE the first move is Src to Dst.
so if you simply reiterate that, you've failed to answer the question.
The question is how does the program KNOW that even is src to aux and odd is src to dst for the opening move? ? I don't see any distinguishing feature from the program that indicates odd v even.