![]() ![]() ![]() However it is the displaying of the function parameters which is the solution to the problem and crucially understanding the double tree like structure of the calls. moving the remaining tower on the spare peg to the destination peg.moving the last disc to the destination peg.moving a smaller tower to the spare peg.Yes the problem is really in three parts: The magic occurs in the succesive rearrangment of the function parameters. In the Tower of Hanoi, the answer is not in the returned result per se, but in the observation of the returned result. However, this teaches the reader to use the results of the returned result in the next recursive call. After that, the remaining disc will be moved to the destination peg and afterwards the second recursion compeltes the moving of the entire tower, by moving the n − 1 tower from the temp peg to the destination peg, above disc n.Īlthough this is an old post, I think what one really needs to understand, is not the "move this to that" approach but that the answer involves using the side-effect of the recursion.Ī invaluable help to me was the "The Little Schemer" which teaches one to think and write recursive functions. The one before the writeln will move n − 1 discs onto the temporary peg, using the destination peg as temporary storage (the arguments in the recursive call are in different order). The recursion happens actually twice, there, once before the writeln, once after. #MATH PUZZLE WITH MOVABLE DISKS CODE#The code in your post has three arguments, besides the number of discs: A source peg, a destination peg and a temporary peg on which discs can be stored in between (where every disc with size n − 1 fits). #MATH PUZZLE WITH MOVABLE DISKS FULL#And that you have to move them first to another peg than where you want the full tower to appear. It's pretty clear that you first have to remove n − 1 discs to get access to the nth one. move n−1 discs from B to C so they sit on disc #n.The following table shows the coherence between the number of discs and the number of moves: DiscsĬontact & Copyright | validate: xhtml 1.Actually, the section from where you took that code offers an explanation as well: Therefore the number of discs moves is approximately doubled every time you put another one on it. To move all discs from one pin to another takes 2 D-1 moves where "D" is the number of discs. If you work very quickly and moved, say one disc every second of every hour of every day, it will take over 580,000,000,000 (=580 billion) years to solve, so the sun will explode before that happens! Well… actually the Tower of Hanoi was actually invented in 1883 by the Edouard Lucas (a French mathematician). But don't panic! In order to transfer the 64 disks properly a total of 18,446,744,073,709,551,615 moves are required if you make absolutely no mistakes. When the tower has been transferred from to the other pole, the world would cease to exist. The priests are then to move one disc at a time, putting it on one of the other poles, and never place it onto a smaller disc. This is the Tower of Brahma, but is also called the tower of Hanoi. During the Creation God placed 64 golden disks on one of these poles and they were stacked from large to small. There is a legend about the puzzle and it goes as follows: In the temple of Benares, at the center of the world, there were three diamond poles on a copper plate. I have tested it to work on the following browsers: Firefox, Internet explorer 6 for windows, Safari, Mozilla and Camino. If at start there is a disc at the middle peg your browser is unluckily incompatible. If you want the computer to solve it simply press start after choosing speed. To move the discs simply use the buttons right under the pegs. Solve slowly:Your computer solves the puzzle slowly.Solve normally:Your computer solves the puzzle at normal speed.Solve quickly:Your computer solves the puzzle quickly.Cheat:You can do all moves, including illigal ones.Teacher:You move but you are alerted if you do a wrong move.User: You move the blocks, but the computer stops you from cheating.You can either have the solved by the computer or you can solve it yourself by choosing one of the following modes: When you have chosen how many discs you want you must choose which course of action you want. ![]() This is an electronic version of the puzzle. You may only move one ring at a time and you must never allow a larger ring to rest on a smaller ring. It is a puzzle where the object is to move all of the rings to the right most peg. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |