12/16/2023 0 Comments Hanoi towers 3 discs![]() Recursive SolutionĪlthough the monks devoted their lives to solve this problem, we won’t. This representation will be used in the following sections. (T,S,D,n) means the source is peg 2, destination is peg 3 and temp is peg 1. Therefore (S,T,D,n) represents the problem to transfer n disks from the source to destination through temp, when source is peg 1, temp is peg 2 and destination is peg 3. That is, the first, second and third location of the tuple represents the source, temp and destination poles for the current problem, and the third element the number of rings. The first location in the tuple denotes the initial letter of the source peg name, the second location in the tuple denotes the initial letter of the temporary peg name, and the third location in the tuple denotes the initial letter of the destination peg name and the fourth location denotes the number of disks for the current problem being solved. Let us define (S,T,D,n) as a problem instance where we need to move the disks from Source to Destination through Temp. The constraints are that only one ring can be moved from one peg to the other in one move, and a larger ring cannot be placed on top of a smaller ring. The task is to move this column on rings from the Source peg to the Destination peg using the Temp peg as temporary storage of the rings. There are n concentric rings of different sizes on the Source peg in such a way that the bottom most ring is the largest and the topmost ring is the smallest and a larger ring is not placed on a smaller ring. There are three pegs Source, Temp, Destination. In this post I will describe the basic recursive solution to the Towers of Hanoi ![]() It is not clear whether Lucas invented this legend or was inspired by it. According to the legend, when the last move of the puzzle is completed, the world will end. The puzzle is therefore also known as the Tower of Brahma puzzle. Brahmin priests, acting out the command of an ancient prophecy, have been moving these disks, in accordance with the rules of the puzzle, since that time. There is a legend about an Indian temple which contains a large room with three time-worn posts in it surrounded by 64 golden disks. The puzzle was invented by the French mathematician Édouard Lucas in 1883. The constraints are we can move only one disk at a time, and we may use the third peg as a temporary storage for the disks, and a larger disk cannot be placed on top of a smaller disk. The task is to transfer such a column of disks from a source peg to another destination peg. Towers of Hanoi is a mathematical game or a puzzle in which there are three pegs, and some disks (originally 8) of different radius placed on top of one another such that no larger disk is placed on a smaller disk.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |