Tower of Hanoi
#2165Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude DesktopThe Tower of Hanoi game consists of three stacks (left, middle and right) and round disks of different sizes. Initially, the left stack has all the disks, in increasing order of size from top to bottom.
The goal is to move all the disks to the right stack using the middle stack. On each move you can move the uppermost disk from a stack to another stack. In addition, it is not allowed to place a larger disk on a smaller disk.
Your task is to find a solution that minimizes the number of moves.
Input
The only input line has an integer : the number of disks.
Output
First print an integer : the minimum number of moves.
After this, print lines that describe the moves. Each line has two integers and : you move a disk from stack to stack .
2
3 1 2 1 3 2 3
Tools
2
3 1 2 1 3 2 3