![]() The rules of the problem require that these lists must always be decreasing sequences. To do moveTower(height-1,w,x) you are allowed to place all the remaining disc in all the 3. That works because you can move each disc of the tower of height h-1 on the largest disc. The initial state of the system, with all discs on pole A is denoted by, for example, A = where the first indexed item is the "bottom" of the pole and the last indexed item is the "top". That is the usual solution for Hanoi: move the tower of height h-1 to the withPole, move the largest disc to the endPole and move tower of height h-1 to the endPole. In the following code, we identify the discs by the integers $1,2,3,\cdots$ stored in one of three lists, A, B and C. The second step is a single move, but the first and last require the movement of a stack of $n-1$ discs from one peg to another - which is exactly what the algorithm itself solves! The Tower of Hanoi (also called the Tower of Brahma or Lucas’ Tower1 and sometimes pluralized as Towers) is a mathematical game or puzzle.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |