Problems
There is a legend about the Tower of Hanoi:
In a temple in ancient India's Benares (present-day Hanoi, Vietnam), there is a great dome said to represent the center of the world.
Inside it stand three diamond pillars placed on a bronze plate.
On one of the pillars, God placed 64 golden disks.
The largest disk is at the bottom, and the remaining disks become smaller as they stack toward the top.
This is the sacred Tower of Brahma.
Following Brahma’s command, monks climb to the altar day and night and move the disks one by one according to the rules in order to transfer all disks to another pillar.
When this task is completed, the tower will collapse and the world will meet its end.
Number the pillars as 1, 2, and 3, and number the N disks from 1 to N, where 1 is the smallest.
All disks begin stacked in order on pillar 1.
Move all disks to pillar 3 following the rules below:
Only one disk may be moved at a time.
A larger disk may not be placed on top of a smaller disk.
When all disks are stacked on pillar 1, write a program to output the full sequence of moves required to transfer all disks to pillar 3 in the minimum number of moves.
Input
The number of disks N stacked on pillar 1 (1 ≤ N ≤ 15).
Output
Print each move on a separate line in the format: diskNumber : fromPeg -> toPeg
Example
3
1 : 1 -> 3
2 : 1 -> 2
1 : 3 -> 2
3 : 1 -> 3
1 : 2 -> 1
2 : 2 -> 3
1 : 1 -> 3