With the new millenium approaching fast (by the way, what is the first year of the new millenium?), scary stories about the end of the world multiplicate like mushrooms after a healthy rain.
Of course there are plenty of arguments pro and against such a terrible claim. While some people have the end of the century and of this millenium as the time target for their predictions, others have different ideas. Here is a (made up) legend about the end of the world.
``In the great temple at Benares, beneath the dome which marks the centre of the world, rests a brass plate in which are fixed three diamond needles, each a cubit high and as thick as the body of a bee. On one of these needles, at the creation, God placed sixty-four discs of pure gold, the largest disc resting on the brass plate, and the others getting smaller and smaller up to the top one. This is the Tower of Bramah. Day and night unceasingly the priests transfer the discs from one diamond needle to another according to the fixed and immutable laws of Bramah, which require that the priest on duty must not move more than one disc at a time and that he must place this disc on a needle so that there is no smaller disc below it. When the sixty-four discs shall have been thus transferred from the needle on which at the creation God placed them to one of the other needles, tower, temple, and Brahmins alike will crumble into dust, and with a thunderclap the world will vanish.'' 
This story is also known as the `Towers of Hanoi" problem. We wonder whether it is indeed possible to transfer the disks from one needle to another following the rules, and most important, how much this would take.
We will denote the three diamond needles by A, B and C. Initially the disks are on A. Their final position will be C. The figure below only shows four golden disks in their initial position.
Your main job is to find a computer algorithm which would do the same job the monks do. Here is a detailed description of what you have to do:
1. Implement the algorithm using C/C++. The program, called hanoi, will accept command line arguments as follows
hanoi -n disks [ -v ] [ -h ]
where the square brackets indicate that the parameter is optional, the user may or my not use it. disks indicate the number of disks to start with on needle A. The flag -v indicates that the output should be verbose, your program will print a line at each move, indicating what move is performed as in this sample output:
move disk 1 from A to B move disk 2 from A to C
When the -h flag is used in the command line, the program prints a statement about how the program should be used and stops.
The smallest disk is number 1. After the disks have been all moved, the program prints the number of moves it took to complete the job and the running time.
2. Find out how many moves are necessary to solve the problem if there are N disks.
3. Find the time complexity of the algorithm by measuring the running time (without the -v command line flag) for a number of disks between 10 and 25.
4. Assuming that the monks have already moved 32 disks from A to C, and that they move one disk every second, day and night with no rest whatsoever, when is the world set to colapse?
The algorithm is a direct application of recursion. Before you write the program try to understand how it works by using a small number of disks (1, 2, 3, ...)
 R. R. W. Ball, Mathematical Recreations and Essays, 1982, Macmillan, London.
(c) 1996, Virgil Bistriceanu - email@example.com
Posted: September 14, 1996
Last update: September 14, 1996