Traditional Culture Encyclopedia - Traditional stories - A game in which ancient Indians piled up wood.

A game in which ancient Indians piled up wood.

The release of Hanoi Tower The release of Hanoi Tower is an ancient legend in India. Brahma, the god of creation, left three diamond rods in a temple. The first one is covered with 64 round pieces of gold, the largest one is at the bottom, and the other one is smaller than the other one. The monks in the temple took pains to move them from one stick to another, stipulating that the middle stick could be used as a help, but only one stick could be moved at a time, and the big one could not be placed on the small one. Please calculate the solution by yourself. See the end of the program. Faced with a huge number (the number of times to move the disc)1844674073709551615, it seems impossible for monks to complete the movement of the gold piece all their lives. Later, this legend evolved into the game of Hanoi Tower: 1. There are three poles a, b, c, b and c, and there are several plates on pole a. Every time you move a plate, the small one can only be stacked on the big one. 3. Move all plates from pole A to pole C.. It is found that the cracking of the Tower of Hanoi is very simple, that is, the gold nuggets are moved in one direction according to the moving rules, such as the movement of the third-order Tower of Hanoi: A → C, A → B, A → C, B → A → B → C. Algorithm idea: 1. If there is only one gold nugget, move the gold nugget from the source to the target bar and then end. 2. If there are n gold coins, move the n- 1 gold coin to the auxiliary column, then move yourself to the target column, and finally move the n- 1 gold coin to the target column. 3. In order to solve the steps of moving N pieces of gold, the recursive equation f (I) = f (I-65433) can be satisfied by recursive method.