Home › Games › 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.
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.
| Cards | Places | Minimum moves |
|---|---|---|
| 3 | 3 | 7 |
| 4 | 3 | 15 |
| 5 | 3 | 31 |
| 6 | 3 | 63 |
| 7 | 3 | 127 |
| 8 | 3 | 255 |
| 9 | 4 | 41 |
| 10 | 4 | 49 |
| 12 | 4 | 81 |
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.
| Pairs | Places | Minimum moves |
|---|---|---|
| 2 | 3 | 9 |
| 3 | 4 | 13 |
| 4 | 4 | 21 |
| 3 | 3 | 25 |
| 5 | 4 | 31 |
| 4 | 3 | 59 |
| 5 | 3 | 131 |
| 6 | 3 | 277 |
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.
Also in Decks
- Black Hole Solitaire — rules and strategy
- Double Klondike — two-deck solitaire with nine columns
- FreeCell Solitaire — rules, moves and strategy
- Golf Solitaire — rules and strategy
- Klondike Solitaire — rules, five levels and strategy
- Memo — the memory card game, four sizes
- Pyramid Solitaire — rules, levels and strategy
- Spanish Solitaire — Klondike with a 40-card Spanish deck
- Spider Solitaire — 1, 2 and 4 suits
- TriPeaks Solitaire — rules and strategy