lohahook.blogg.se

Hanoi towers puzzle
Hanoi towers puzzle













Now let us try to derive a general formula. A trained mathematician would also note that T 0 = 0. One can easily convince oneself that T 2 = 3 and T 1 = 1. From the previous section T 3 = 7 and T 4 = 15. Let T N be the minimum number of moves needed to solve the puzzle with N disks. Of course "Move" means moving the topmost disk. To me the sheer simplicity of the solution is breathtaking. 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. This actually serves as the definition of the function Solve. Then the body of the function might look like Move N - 1 disks from Aux to Dst (using Src as an intermediary peg)Īssume there is a function Solve with four arguments - number of disks and three pegs (source, intermediary and destination - in this order).Move the top N - 1 disks from Src to Aux (using Dst as an intermediary peg).

Hanoi towers puzzle how to#

Know how to accomplish the following tasks: Therefore, for a given number N of disks, the problem appears to be solved if we After moving the bottom disk from Src to Dst these disks will have to be At this point in time all the remaining disks will have to be stacked However one solves the problem, sooner or later the bottom disk will To better understandĪnd appreciate the following solution you should try solving the puzzle for small number of disks, Let call the three pegs Src (Source), Aux (Auxiliary) and Dst (Destination). Try IE11 or Safari and declare the site as trusted in the Java setup. If you are reading this, your browser is not set to run Java applets. The applet expects you to move disks from the leftmost peg to the rightmost peg. You can drop a disk on to a peg when its center is sufficiently close to the center of the peg. To solve the puzzle drag disks from one peg to another following the rules. The applet has several controls that allow one to select the number of disks and observe the solution in a Fast or Slow manner.

hanoi towers puzzle

Its solution touches on two important topics discussed later on: The puzzle is well known to students of Computer Science since it appears in virtually any introductory text on data structures or algorithms.

hanoi towers puzzle

The objective is to transfer the entire tower to one of the other pegs (the rightmost one in the applet below), moving only one disk at a time and never a larger one onto a smaller. We are given a tower of eight disks (initially four in the applet below), initially stacked in increasing size on one of three pegs. I cut the 1/4" dowel into three 3 1/2" lengths for the pegs.Īfter sufficiently sanding the base board, use wood glue to secure the pegs to the board.The Tower of Hanoi puzzle was invented by the French mathematician Edouard Lucas in 1883. I drilled 90% of the way through the board to avoid the dowels from being visible from the bottom of the board. (reference the fourth picture above)įinally, I used a 1/4" brad-point drill bit to drill these holes where the dowels will snugly sit. I marked the middle peg hole at the exact center, and the other two holes were located 3 1/4" from the center. To do this, I used a tri-square to find the exact center of the board and drew a straight line dividing the board lengthwise into two pieces. After this, I ran the board horizontally through the joiner, once on both sides to really straighten up the board.Īfter the board was made nice and square, I finalized its length by cutting it to 10".Īt this point, it was time to mark where to drill the holes for the pegs to be placed. I cut the straightest section of the board out, then ran the board vertically through the joiner to straighten the edges. I chose a piece of poplar pallet wood that was 3 1/4" wide.













Hanoi towers puzzle