Towers of Hanoi

image

The Towers of Hanoi is a game that consists of three rods and nn disks of different sizes that can slide onto any rod. The game starts with the disks stacked in order of size on the left rod, the biggest disk at the bottom. The aim of the game is to move all the disks from the left rod (A) to the right rod (C), using the middle rod (B) as auxiliary. All the moves have to follow these rules:

Write a program that solves the game of the Towers of Hanoi, using the minimal number of movements.

Input

Input consists of a single natural number nn between 1 and 18.

Output

Print the shortest sequence of movements for the given nn. Follow the format of the examples.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:05:39.417Z

© Jutge.org, 2006–2026.
https://jutge.org