LearnPy Hub
← Recursion & Lambda problems
Hard

Tower of Hanoi

Move n disks from peg A to peg C using peg B. Print each move as A -> C, then the total number of moves.

Input

One integer 1 ≤ n ≤ 6.

Output

The moves, then the count.

Sample 1

Input
2
Output
A -> B
A -> C
B -> C
3

Sample 2

Input
1
Output
A -> C
1
solution.py
Output appears here
Tower of Hanoi · Python practice problem · LearnPy Hub