Game of Nim
Take turns picking up sticks, and don't let the fox take the last one. Twelve levels to learn the strategy that wins.
Ages 6 and up
Leaderboard
Loading leaderboard…
A row of sticks lying on the table. Across from you, a smiling fox. You take turns picking up sticks; whoever takes the last one wins. That is all. There is nothing to memorize, nothing to read, no hidden card: everything is on the table, and yet there is a way of playing that wins every single time. The game of Nim is probably the oldest two-player puzzle whose complete solution we know, and that is exactly what makes it so gripping: you are not playing against luck, you are playing against an idea you have not found yet.
The fox knows that idea — well, not right away. On the first level it plays any old way and gets beaten without even noticing. Later it starts to think, slips up about one time in three, and pulls a face when it realizes its mistake. On the last levels it never makes a mistake at all: at that point, if you play right from the first move, you win; if not, it will not give you a single chance. That rising strength is what makes the game worthwhile: an opponent who is perfect from the very first game teaches nobody anything, but an opponent who grows with you forces you to understand.
If you are looking for the game of Nim to play online against the computer, a fun way to discover a real winning strategy, or a math game that teaches reasoning without a single equation, this one takes you from the classic 21-stick game all the way to misère Nim, one level at a time.
How to play
Tap a stick: that stick and every one after it, to the end of its row, light up. That is your take. If you are happy with it, tap Take; if not, tap another stick and the selection changes. Nothing is final until you press the button, so you can try out as many selections as you like before you decide.
On a keyboard, it is even faster: the up and down arrow keys change rows, the left and right arrow keys lower or raise the number of sticks you take, and Enter confirms. The game plays entirely without a mouse, and every take is announced for screen readers.
A stick you take does not vanish: it lies down, blackened, its head still smoking, and it stays where it was. So you can always see what is left and what is gone — and the color of the burnt head tells you who took it, you or the fox. It is a small detail, but it changes everything when you want to understand afterward how the game turned.
Each level shows its three rules at the top of the screen: how many sticks you can take at once, whether you must stay in a single row, and above all who wins at the end. That last point flips in the third world, and the banner turns red so you do not forget.
The three worlds
The 21 sticks. A single row, twenty-one sticks, and you take one, two or three on each turn. Whoever takes the last one wins. This is the best-known version, the one people play with matchsticks at the table while waiting for dessert. The four levels of this world change the numbers to keep you from learning a recipe by heart: eighteen sticks taking up to four at a time, then twenty-five sticks against a fox that forgives nothing.
The Marienbad game. Several rows, and a single constraint: you take as many sticks as you like, but all from the same row. The most famous position is four rows of one, three, five and seven sticks — it owes its name to a 1961 film, Last Year at Marienbad, in which two characters play it over and over, and one of them always wins. The world starts gently on three short rows, opens up to four rows, and ends on three rows against a fox that plays perfectly.
Upside down. The rule turns around: whoever takes the last stick loses. Everything you have learned stays true almost to the very end, and turns false in the last few moves. It is the trickiest world, and the most satisfying to figure out. It starts on a single row, then widens to four and five rows against a perfect fox.
Stars and progress
Each level is worth up to three stars.
- One star as soon as you win, however you do it.
- Two stars if you win without asking for a single hint.
- Three stars if, on top of that, you played perfectly: every time the position let you take the upper hand, you did.
A single star is enough to unlock the next level, and losing costs you nothing at all: the fox celebrates loudly, the level restarts with one button, and nothing is taken away. You can go back to any level you have already opened from the level map to collect the stars you are missing.
When you lose, the game shows you where it happened: the end panel tells you on which move you handed the advantage back to the fox, and what you should have taken instead. It is often much earlier than you thought.
Your stars and unlocked levels are saved in your browser. If you switch devices or clear your browser's data, the level map starts from scratch — and that is fine, the second time through goes much faster. The twelve levels are the same for everyone, and you play them at your own pace.
Leaderboard
Every level you win earns points, and your leaderboard score is the total of all your levels. Points follow stars, and later worlds are worth more: in the first world, three stars earn 50 points, two earn 40 and one earns 30; the second world pays double, the third triple. Winning all twelve levels with no hint and no slip adds up to 1,200 points. Asking for a hint brings the level down to one star, so 30 points in the first world and 90 in the third: that is the price of the explanation, and nothing stops you from coming back to win the level on your own.
Each level counts once, for your best game. Replaying a level for more stars raises your total; replaying it worse, or losing it, costs you nothing. The leaderboard only keeps verified games: the server replays every move you made, recomputes each of the fox's replies exactly as it played them against you, and recounts your stars before it accepts the score. The first time you win a level, the game asks for a nickname, and from then on your total is sent on its own without interrupting your game.
The hint, and why it explains
The Hint button does not just play for you. It puts the selection on the right move and tells you in one sentence why it is right: it will leave the fox a multiple of four, the two rows will be equal so you can copy each of its moves, it will leave an odd number of single-stick rows. After three or four hints, the rule of the world appears on its own.
Using a hint costs you the second and third stars for that game, but never the ones you have already won. In other words: use it without guilt the first time, then replay the level without it.
At the end of each world, a clear panel sums up the complete strategy in three paragraphs, with examples. That is where the game turns into a short math lesson, without ever writing an equation.
Tips and the winning strategy
- Count what you leave, not what you take. In the single-row version, do not look at how many sticks you take: look at how many you leave. The number left behind is what wins or loses.
- The complement rule. If you can take one to three sticks, always leave a multiple of four. Then complete each of the fox's takes to four: it takes one, you take three; it takes two, you take two. The pile goes down by four each round, and the fox ends up facing the last four.
- Change the target when the rule changes. When you can take one to four sticks, the target is no longer four but five. The general rule: if you can take up to k sticks, leave a multiple of k + 1.
- Break the rows into bundles. With several rows, write each size as a sum of eight, four, two and one: seven is four plus two plus one, five is four plus one, three is two plus one. Your position is good when each bundle size appears an even number of times.
- Two equal rows, and you have won. As soon as only two rows of the same size are left and it is the fox's turn, all you have to do is copy each of its moves in the other row.
- Upside down, watch the single-stick rows. As long as one row still holds at least two sticks, play exactly as in the previous world. As soon as only single-stick rows are left, leave the fox an odd number of them.
- Watch the fox. When it pulls a face, it has just made a mistake: the position is winning for you again, so do not waste it on the next move.
Frequently asked questions
Is the game of Nim a game of chance? No, not at all. Everything is visible on the table and nothing is drawn at random. From any position, one of the two players has a way of playing that wins for sure: the whole question is which one, and how.
What age is it for? The first world makes sense from six or seven years old: all you need is to count up to twenty-one. The second world takes a bit more patience, and the third keeps plenty of adults entertained.
Does the fox cheat? Never. It only looks at what you can see too, and it follows the same rules as you. On the first levels it plays at random, then it plays one move in three at random, which is not always a mistake, and on the last levels it plays perfectly — but "perfectly" does not mean "unbeatable": every level starts from a position you can win.
Why does the fox sometimes go first? Because some famous positions, like one-three-five-seven, are lost for whoever plays first. Handing them to you by making you start would be unfair: so the fox opens, and it is up to you not to let it back into the game.
What is the misère rule? It is the technical name for the upside-down rule of the third world: whoever takes the last stick loses instead of winning. The strategy stays almost the same, except in the very last moves, and that "almost" is what makes the world hard.
Do I need to be good at math? No. The game's explanations only use multiples, pairs, and odd and even numbers. The link with mathematics is real — Nim is even a classic example — but you can win every level without ever thinking about it.
Are my stars saved anywhere? They are kept in your browser, on this device, along with your best game on each level. There is no account to create: a nickname is all you need to appear on the leaderboard, and only your total is compared with other players'.
Is there a leaderboard? Yes: it ranks players by the total points of the levels they have won, up to 1,200. The twelve levels are the same for everyone, and you play them at your own pace.
Does the game work on a phone? Yes. You tap the sticks with your finger, the confirm button is big, and the layout adapts to your screen. On a computer, the game also plays entirely with the keyboard, using the arrow keys and Enter.
More educational games
Educational games- Multiplication Tables
Feed a hungry monster: tap the fruit with the right answer, and watch it grow. - World Map Quiz
A country is named, you tap it on the map. 162 countries, every continent, ten levels with stars to earn. - Tower of Hanoi
Move the tower disk by disk, never putting a big one on a small one. Ten levels, up to twelve disks and four pegs. - Plant Cell and Photosynthesis
Spot the organelles on a real textbook diagram, then switch on photosynthesis and watch the leaf come to life. - Wolf, Goat and Cabbage
The wolf eats the goat, the goat eats the cabbage: get everyone across. Twelve puzzles, and fails that make you laugh. - Electric Circuits
Turn the wires, close the loop and light the bulbs: series, parallel and short circuits, in twenty-four levels. - Tangram
Seven pieces, one shadow to fill: thirteen shapes and an album to complete. - Logic Gates
Place the right gates, flip the switches and make the lamp follow the whole truth table.