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. 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. 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. Likewise, we can make a recursive formula to compute how many moves the algorithm will require.The Tower of Hanoi puzzle was invented by the French mathematician Edouard Lucas in 1883. We can make a recursive algorithm out of this, with the recursion occurring each time the number of disks to move is reduced by 2. In fact, you now have the same problem you started out with, but with N−2 disks on peg B instead of N disks on peg A, and you need to move disk N − 3 to peg A Do all of this, so now you have disks N and N − 2 on peg A and all the other disks on peg B.įortunately, you do not have to move disk N − 3 again, because it is already exactly where you want it (on top of disk N − 1). But in order to do this you have to move all the smaller disks from peg C to peg B. You have to get disk N − 2 onto peg A. So now you have disk N on peg A, disk N − 1 on peg B, and all the other disks on peg C. In order to do that, you must first move disks 1, …, N − 2 1, …, N − 2 to peg C. WLOG, suppose you decide to move disk N − 1 to peg B. Without loss of generality (WLOG), suppose they are all on peg A at the start.ĭisks N and N − 1 are different colors, so at a minimum you must move disk N − 1 off of disk N and onto another peg. Let the disks be numbered 1,…, N 1,…,N from smallest to largest. What are least number of moves she will need in order to get the location of the next puzzle ? Now Fleur is given 6 discs of each colour( n = 6) arranged in the same way as the initial configuration. The biggest discs at the bottom of the towers are assumed to swap positions. The goal of the puzzle is to arrange all red discs on one tower, and all green discs on another. Also, there are now two towers of disks of alternating colors. The difference is that now for every size there are two disks: one green and one red. At no time may a bigger disk be placed on top of a smaller one. The rules of the puzzle are essentially the same: disks are transferred between pegs one at a time. The following variation of the famous TOWER OF HANOI puzzle was offered to Fleur Delacour by Madame Maxime in order to get the location of the next puzzle by Madame Maxime which was locked inside a box. For instance if we take 3 discs in 1st peg saying it as peg A it will take 7 steps to take it to 2nd peg. A larger disc cannot be placed on a smaller disc. Only one disk can be moved among the towers at any given time.ģ. A few rules to be followed for Tower of Hanoi are −ġ. Rules: The mission is to move all the disks to another tower without violating the sequence of arrangement. There are other variations of the puzzle where the number of disks increase, but the tower count remains the same. the smaller one sits over the larger one. These rings are of different sizes and stacked upon in an ascending order, i.e. Tower of Hanoi, a famous Beauxbatons puzzle which consists of three towers (pegs) and more than one rings, is as depicted −
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |