1The Legend
2The Rules
3The Challenge
4Reflect
5The Reveal
6Workbook
Chapter 1 · The Legend

🛕 The Tower of Brahma
ब्रह्मा की आयु

In the great temple of Kashi Vishwanath, so the legend goes, priests tend a brass plate fitted with three rods.

On the first rod rest 64 discs of pure diamond, each one smaller than the one beneath it, the largest at the bottom.

Day and night the priests move the discs, one at a time, from the first rod to the third. The legend says that when the very last disc is placed, the universe will come to an end.

So how long do the priests actually need? To find out, we'll start with a much smaller tower 👇

Chapter 2 · The Rules

The Priests' Rules

The brass plate has three rods: Rod 1, Rod 2, and Rod 3.

Rod 1 holds the tower of discs, largest at the bottom, smallest at the top.

The mission: move the entire tower from Rod 1 to Rod 3.

The priests may use Rod 2 along the way, but only as a temporary resting place.

Before the priests face 64 discs, let's try it with just 3.

Chapter 3 · The Challenge

Try It: Move 3 Discs

Click a rod to pick up its top disc, then click another rod to place it there.

🔢 Moves: 0
🛕
THE PRIEST SAYS Click Rod 1 to pick up its top disc. Then click another rod to place it there.
Chapter 4 · Reflect

Think back on your game

Take a minute to look back at what you just did. There are no right answers here, just think each one over in your own words.

1 · Finding the Best SolutionIf multiple valid move sequences can solve the puzzle, how would you decide which one is optimal?
2 · Why Does Disc Order Matter?Why must smaller discs stay above larger discs, and what could go wrong if this rule were reversed?
3 · Making the Biggest MoveWhy must the smaller discs be moved out of the way before the largest disc can reach its destination?
4 · Planning AheadHow did solving the puzzle change when you started thinking about smaller tasks instead of moving individual discs?
5 · Recognising a PatternWhat pattern did you observe in the minimum number of moves as each new disc was added?
Chapter 5 · The Reveal

What your hands were really doing

Let's walk back through the moves you made, one idea at a time, starting with the smallest tower possible.

1 One disc is easy

Start with the simplest tower there is: a single disc. Nothing sits on top of it and nothing is in the way, so you just pick it up and put it on Rod 3. One move, no planning.

When a problem gets so small that you can just do it, that's the base case. It's the point where all the thinking stops.

2 Two discs: the small one steps aside

Now put a bigger disc underneath. You can't touch the big one while the small one is sitting on it, so the small disc has to get out of the way first. That makes 3 moves: small disc aside, big disc across, small disc back on top.

3 Three discs: same trick, one size up

You probably felt this one in your hands. To free the biggest disc, you had to move the top two discs onto Rod 2. And that's exactly the 2-disc puzzle you just saw, only with the rods playing different roles. After the big disc crosses, you solve that same 2-disc puzzle again to bring them over.

Move the top n−1 discs onto Rod 2
Move disc n to Rod 3 (just 1 move)
Move those n−1 discs onto Rod 3

n−1 discs, then 1 big move, then n−1 discs again

That plan works for any tower. Notice that the two “move n−1 discs” jobs are the very same problem you started with, just smaller. Handing that smaller tower to the same set of steps is called a recursive call, and the whole “n−1 twice, plus one big move” plan is the recursive case.

4 Who is waiting for whom?

While you were parking the top discs on Rod 2, the job “move the biggest disc” hadn't happened yet. It was on hold, waiting for the smaller job to finish. A program keeps track of those paused jobs in a call stack. Here's the 3-disc case:

Once the smallest job is finished, it drops off the stack, and the job underneath it wakes up and carries on from exactly where it paused. That step back is called returning.

Curious how this looks in code? (optional)
# move n discs from one rod to another
def move(n, start, end, spare):
    if n == 1:
        print("move disc 1:", start, "->", end)   # base case
        return
    move(n - 1, start, spare, end)    # clear the way
    print("move disc", n, ":", start, "->", end)   # the one big move
    move(n - 1, spare, end, start)    # bring them back on top

5 Counting the moves

Let T(n) be the fewest moves needed for n discs. From the plan above, we make two trips with n−1 discs, plus one move for the biggest disc:

T(n) = 2 · T(n−1) + 1  and  T(1) = 1

Let's use it on small towers first:

Discs (n)WorkingT(n)2n
1base case12
22 × 1 + 134
32 × 3 + 178
42 × 7 + 11516
52 × 15 + 13132

Spot it? Every answer is exactly one less than a power of 2. Here's why that always works:

Add 1 to both sides of the rule: T(n) + 1 = 2 · (T(n−1) + 1)
So T(n) + 1 doubles every time we add a disc, starting from T(1) + 1 = 2.
That means T(n) + 1 = 2n, so T(n) = 2n − 1.

6 Now try 64 discs

With the formula in hand, let's go back to the priests of Kashi Vishwanath. Slide the number of discs up and watch how fast the numbers run away.

⏳ The Brahma Clock

moves = 2n − 1
Discs: 5
31
Moves needed
31 seconds
at 1 move per second
Time needed

That is 0% of Brahma's entire lifespan (311 trillion years).

🕉️ How long does Brahma live?

  • Bhagavad Gita, Chapter 8, Verse 17: a single day of Brahma lasts 1,000 Mahayugas, and his night lasts just as long.
  • That's about 4.32 billion solar years for the day, and the same again for the night.
  • Brahma's life is 100 Brahma years, about 3.11 × 1014 solar years (311 trillion years). This is the lifecycle of the universe itself.

🛕 So, what does the legend say? With 64 discs the priests need 264 − 1 moves, about 1.84 × 1019 (roughly 18.4 quintillion). Even at one move every second, that's over 580 billion years. It sounds endless, but Brahma's life is about 311 trillion years, so the priests' whole task is just a tiny slice of it. By the Hindu cosmic timeline, the present Brahma's life is far from over, which means the end of the universe is still very, very far away.

🏛️ A small note on the story. In the West this puzzle is called the Tower of Hanoi. It's the way of solving a big problem by handing a smaller copy of it to the same steps.

Chapter 6 · Exercise Workbook

Try it on new problems

Seven questions to think through at your own pace. There is no single right answer, so take your time.

1 · One Puzzle, Different NamesHow are the Tower of Hanoi and Lucas's Tower related? Does giving the same puzzle a different name change its rules or solution?
2 · The Tower of VeniceIf your Venice-inspired version introduces a new movement restriction, how would that change the original Tower of Hanoi solution?
3 · Beyond Three RodsIf an extra rod makes the puzzle easier, does adding more resources always make a computational problem easier? And how much easier does it become?
4 · Recursion vs. IterationHow could you solve the Tower of Hanoi using a loop instead of recursion? What would the iterative approach need to keep track of?
5 · Choosing RecursionWhy might recursion make the Tower of Hanoi solution easier to understand, even though an iterative solution is also possible?
6 · Beyond the TowersHow could recursion help find every file inside a folder that contains nested subfolders?
7 · When Recursion Is UsefulConsider a family tree in which each person may have children and grandchildren. How could recursion help display all descendants?
🏆 Achievement unlocked