Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 729 Bytes

File metadata and controls

19 lines (15 loc) · 729 Bytes

Problem 19: Tower Transfer (Tower of Hanoi)

Problem Statement

The Tower of Hanoi is a classic mathematical puzzle. You have 3 rods and n disks. The objective is to move all n disks from the source rod to the target rod using an auxiliary rod, following these rules:

  1. Only one disk can be moved at a time.
  2. A disk can only be placed on top of a larger disk or an empty rod.
  3. Each move consists of taking the top disk from one rod and placing it on another rod.

Print each move as "Move disk X from Rod A to Rod C".

Input Format

  • An integer n (number of disks).

Example

Input: n = 2
Output:
Move disk 1 from Rod A to Rod B
Move disk 2 from Rod A to Rod C
Move disk 1 from Rod B to Rod C