Talk:Towers of Hanoi: Difference between revisions

m
added a section header to the 1st topic so that the table of contents is in the correct place.
m (added a section header to the 1st topic so that the table of contents is in the correct place.)
 
(3 intermediate revisions by 2 users not shown)
Line 1:
== recursion redirect? ==
Why does recursion redirect here? This isn't the only task that can be solved with recursion. I'd almost prefer to see a category dedicated to recursion, with pages with recursive examples added to that category. --[[User:Short Circuit|Short Circuit]] 23:43, 7 November 2007 (MST)
:I could try my hand at making it for you and finding articles that fall under the category. I may need a small amount of instruction to get me going though. --[[User:mwn3d|mwn3d]] 15:22, 8 November 2007 (EST)
Line 4 ⟶ 5:
 
== Who or what is "Towers of Hanoi"? ==
 
There seems to be some assumption here that everyone
and their aunt must be intimately familiar with the "Towers of Hanoi"
Line 14:
 
== Verbose explanation for J ==
 
Here is one of the J implementations:
 
Line 27 ⟶ 26:
First off, note that this rephrasing has introduced two new names and has also replace anonymous recursion (<code>$:</code>) with non-anonymous recursion (<code>H</code>) -- it would be bad to have the recursion happen purely within thenPart without the conditional which was in the original definition of H.
 
But, wait, why does ''else'' come before ''then''? (For the same reason that 0 comes before 1.:) The primitive <code>@.</code> uses its right argument to come up with an index which is used to select from the code fragments on the left.
 
In this case, the right argument to <code>@.</code> is <code>*</code> which returns 0 for zero arguments and 1 for positive arguments. So the test, in essence is: is the right argument greater than zero?
Line 77 ⟶ 76:
In other words, for H n, we find H n-1 and use that result twice:
 
First, we use it (the previous hanoi solution) keeping our starting point the same, and swapping the use of the other two pegs. Then (after we have moved our disk from peg 0 to peg 2), we use it again but holding the end point the same and swapping the use of the first two pegs.
 
(Some people might feel they should object to this remapping of results as inefficient, but this remapping does not make a difference to the [[wp:Big O notation|big O]] efficiency, and in practice should be a [[wiki:PrematureOptimization|minor concern]].)
 
 
== A bunch of sample codes are buggy ==
The bug is that they print ndisk, which is the number of remaining disks to be moved, as if it was the index of the disk to be moved.
Can someone correct these bugs?