How to play Nim
- Choose your opponent: the computer (pick a level and who goes first) or a friend on the same device.
- Under "Rules and options" pick the piles and whether the player who takes the last stone wins (classic) or loses (misère).
- On your turn, tap a stone: it and all the stones to its right in the same pile are picked. Then tap "Take".
- You take turns until the last stone is taken. In the classic version, whoever takes it wins; in misère, they lose.
Nim strategy
Nim is a solved game: there is a way to play that always wins from winning positions. It is based on the "nim-sum": write the number of stones in each pile in binary and add them without carrying (XOR). If the result is zero, the position is bad for the player who has to move; if it isn't zero, there is a move that makes it zero.
With piles of 3-4-5, the player who starts can always win with correct play. With 1-3-5-7 it's the opposite: the first player loses if the opponent makes no mistakes. In misère the strategy is the same until the end, when you have to leave an odd number of piles with a single stone.
The hard level plays the perfect strategy; medium plays it some of the time; easy plays at random. Everything is calculated on your device and nothing is sent to any server.
Good to know
- If the position is already lost, the hard level still plays the move that drags the game out the longest, hoping for a mistake from you.
- Scores and settings are saved only in this browser.
- Against the computer, Undo takes back your move and its reply; in 2-player mode it takes back the last move.
Frequently asked questions
How do you play Nim?
There are several piles of stones. Players take turns removing one or more stones from a single pile. In the classic version, whoever takes the last stone wins.
What is misère Nim?
It's the same idea in reverse: whoever is forced to take the last stone loses.
Is there a strategy that always wins?
Yes, from any winning position. It's worked out with the binary sum without carrying (XOR) of the piles. Whoever leaves that sum at zero wins.
Can I play with a friend on the same phone?
Yes. Choose the "2 players" mode and take turns.
Is it free? Do I need to install anything?
It's free, needs no sign-up and runs right in your browser.