Tower of Hanoi Problem
📖 Scenario: Imagine you have three rods and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks neatly stacked in ascending order of size on one rod, the smallest at the top, making a conical shape.Your task is to move the entire stack to another rod, obeying the following simple rules:Only one disk can be moved at a time.Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.No disk may be placed on top of a smaller disk.
🎯 Goal: Build a TypeScript program that solves the Tower of Hanoi problem for 3 disks. The program should print each move step-by-step, showing which disk moves from which rod to which rod.
📋 What You'll Learn
Create variables to represent the rods and the number of disks.
Create a recursive function to solve the Tower of Hanoi problem.
Print each move in the format: 'Move disk X from rod Y to rod Z'.
💡 Why This Matters
🌍 Real World
The Tower of Hanoi problem helps understand recursion, a key concept in programming and problem solving.
💼 Career
Recursion is used in many software engineering tasks like parsing, searching, and algorithm design.
Progress0 / 4 steps