## Cyclopian Puzzle

View as PDF

Points: 10
Time limit: 1.0s
Memory limit: 16M

Author:
Problem type
##### PEG 11/12 Programming Test 1 - October 19

There are few in the Cyclopian puzzle market now that FurWear has entered it. Discontent with merely selling clothing, FurWear has ripped off invented a puzzle named after a tower in the Chthonic city of Hanoi.

In FurWear's game, there are three pegs in a line. On the leftmost peg is a tower of discs of unique sizes, sorted with the largest on the bottom and the smallest on the top. The goal is to move the entire tower to the rightmost peg. The challenge lies in that only one disc may be moved at a time, and no disc may be placed atop a smaller disc.

You've bet your colleagues that nobody can solve this puzzle in fewer moves than you. To this end, you've decided to write a program that will show you how to do so and memorise its output.

#### Input Specification

The input consists of a single integer , the number of discs initially on the leftmost peg.

#### Output Specification

You are to output the shortest sequence of moves that will move all discs to the rightmost peg. The pegs are labelled A, B, and C, with A being the leftmost peg and C being the rightmost peg. A move is denoted by the string xy where x is the peg from which a disc is moved, and y is the destination peg. (For example, moving a disc from A to C would be denoted by AC.)

#### Sample Input

4

#### Sample Output

AB
AC
BC
AB
CA
CB
AB
AC
BC
BA
CA
BC
AB
AC
BC