The Tower of Hanoi is a mathematical game or puzzle. It consists of 3 rods, and N disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.
The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
In this problem, you are given 3 rods named rod 1, 2 and 3, with N disks in a stack onto rod 1. Your mission is to move all disks onto disk 2 in minimal steps without breaking the riles provided. You have to print all moves.
You only have to implement the function "hanoi()" to achive the goal. Here is the defination of hanoi():
void hanoi( int rod_N, int rod_A, int rod_B, int rod_C ) ;
rod_N is the number of disks to be move right now, while rod_A, _B, and _C denoted the rod ID, which should be 1, 2, or 3. The function is to "Move the top rod_N disks from rod_A to rod_B via rod_C", and our main() function will hanoi(N, 1, 2, 3) without printing anything.
The input consists of only one positive integers, denoting there are N disks given. At most 8 disks may be given.
For the input, print all required steps of moving. Each move should be printed as an one-lined message like "Move from rod 1 to rod 2.\n". Please replace the rod ID on your own.