Decks

HomeGames › Tower of Hanoi — with cards, three or four places, plus Two Towers

Tower of Hanoi, with cards

The Tower of Hanoi is the oldest puzzle in computer science and one of the simplest to state: move a tower from one place to another, one piece at a time, never putting a larger piece on a smaller one. Decks plays it with cards — the highest card at the bottom, the ace on top — and adds two things the wooden version never had: a fourth place, and a second tower.

Tower of Hanoi from three cards to eight, the four-place variant, and Two Towers — every one solvable in a known number of moves. Free on the App Store.

Download on the App Store
Scan with your phone to installScan with your phone to install

Rules of Tower of Hanoi

The start. One place holds a tower: the highest card at the bottom, the ace on top. The other places are empty.

A move. Take the top card of any place and put it on an empty place, or on a card of higher rank. A lower card never goes on a higher one — that is the whole rule.

Winning. Gather the whole tower on any other place.

How many moves it takes

With three places the minimum doubles with every card: 2ⁿ − 1 moves for n cards. Decks shows the minimum on the game card, and a flawless game hits it exactly.

CardsPlacesMinimum moves
337
4315
5331
6363
73127
83255
9441
10449
12481

Three places: the rule of thumb

With three places there is a simple rule that always works: on odd-numbered moves, move the ace; on even-numbered moves, make the only other legal move. Which way the ace cycles depends on whether the number of cards is odd or even. Follow it and you finish in the minimum without ever thinking.

Four places: the rule is gone

Add a fourth place and the minimum falls dramatically — 41 moves for nine cards instead of 511 — but the rule of thumb disappears with it. The best sequence for four places (the Frame–Stewart algorithm) has to be found by search, and a wrong split of the tower early costs dozens of moves later. This is the version that is a puzzle rather than a ritual, and it is why Decks includes it.

Two Towers

Two Towers is Decks' second Hanoi: a black tower and a red tower stand apart, each from the highest card down to the ace, and the task is to swap them. One concession makes it possible: a card may go on a card of equal or higher rank — equal rank is allowed, lower is not. Without that concession the swap is impossible.

A free place is worth more than a card here: with three places three pairs take twenty-five moves; with four places, thirteen.

PairsPlacesMinimum moves
239
3413
4421
3325
5431
4359
53131
63277

Tower of Hanoi in Decks

Nine sizes of the tower and eight of Two Towers, each with the minimum shown; undo without penalty; a history of every solution and its length. No ads, no account, works offline.

Frequently asked questions

What is the minimum number of moves for the Tower of Hanoi? 2ⁿ − 1 for n discs on three pegs: 7 for three, 255 for eight.

Is there a trick to the Tower of Hanoi? With three pegs, yes: move the smallest piece on every other move, always in the same direction. With four pegs there is no simple trick.

Why does a fourth peg matter? It cuts the minimum from exponential to far smaller — but the optimal strategy becomes a search problem.

What is Two Towers? A variant with two towers of different colours that must be swapped, where a card may sit on an equal card. It is not a classical puzzle; it is Decks' own.

Tower of Hanoi from three cards to eight, the four-place variant, and Two Towers — every one solvable in a known number of moves. Free on the App Store.

Download on the App Store
Scan with your phone to installScan with your phone to install