21 Nim

21 stones on the table. Each turn take 1, 2, or 3. The player forced to take the very last stone loses. Simple rules, deep strategy.

0
You won
0
CPU won

How to use

  1. Take 1, 2, or 3 stones on your turn.
  2. The player who takes the last stone loses.
  3. Play against the CPU (Easy or Hard) or pass the device to a friend in 2-Player mode.

Players take turns removing 1, 2, or 3 stones from a pile that starts at 21. The player forced to take the last stone loses. This sounds like a guessing game but it is actually a pure strategy game with a provably correct winning approach. If you know the strategy, you can always beat a player who does not.

The key insight is that leaving your opponent at a multiple of 4 stones puts you in a winning position because whatever they take (1, 2, or 3), you can always take enough to bring the total back to a lower multiple of 4. Starting from 21, leaving your opponent at 20 wins every time. From there: 16, 12, 8, 4, and finally 1. The player who moves first can guarantee a win.

Frequently Asked Questions

What is the winning strategy for 21?

Leave your opponent at a multiple of 4 on every turn. Since 21 is not a multiple of 4, the first player can always win by taking 1 stone on the first move and responding to each opponent move to maintain multiples of 4.

Can the computer be beaten?

Yes, if you know the strategy and go first. If the computer knows the strategy too, the first player wins every time with perfect play.

Does the same strategy work for different starting numbers?

Yes. The principle extends: for a starting pile of N stones with moves of 1-K allowed, multiples of K+1 are the losing positions for whoever faces them.

Is this a fair game?

No. With both players playing optimally, the first player always wins from 21. The game is more interesting as a puzzle about discovering the strategy than as a competitive game between equal opponents.

21 - Nim Strategy Game | ToolHaven