Nim facts for kids
Nim is a fun and challenging mathematical game played by two people. In Nim, players take turns removing objects (like matches, coins, or stones) from different piles.
Here's how it works:
- On your turn, you must remove at least one object.
- You can remove any number of objects, but they all have to come from the same pile.
- The goal of the game can change:
- In one version, the player who takes the last object wins.
- In another version (called misère play), the player who is forced to take the last object loses.
Contents
What is Nim?
Nim is a type of combinatorial game, which means it's a game where players take turns, there's no randomness (like dice rolls), and players have perfect information about the game's state. It's all about strategy and thinking ahead!
Where Did Nim Come From?
People have been playing games like Nim for a very long time, possibly even since ancient times! Some historians think it might have started in China, where there's a similar game called jiǎn-shízǐ, which means "picking stones."
The first time we see Nim mentioned in Europe was in the early 1500s. The name "Nim" itself was given to the game by Charles L. Bouton from Harvard University in 1901. He also figured out the complete mathematical strategy for winning the game. The name "Nim" might come from the German word nimm, which means "take."
Nim-Playing Machines!
Nim is so mathematical that it was one of the very first games computers were designed to play!
- At the 1939 New York World's Fair, a company called Westinghouse showed off a machine called the Nimatron. This machine played Nim against people. For six months, only a few people managed to beat it! If you won, you got a special coin that said "Nim Champ."
- Later, in 1951, another company called Ferranti built a computer called Nimrod that also played Nim. It was shown at the Festival of Britain.
- Engineers even built a Nim-playing machine out of tinkertoys!
The game of Nim was also featured in a famous column by Martin Gardner in Scientific American magazine in 1958. It even appeared in a French movie called Last Year at Marienbad (1961), where it had a special meaning in the story.
How to Play Nim
Nim is usually played with three piles of objects, but you can play with more or fewer. The number of objects in each pile can be anything you choose to start with.
Normal Play vs. Misère Play
Remember, the goal changes depending on the version:
- Normal Play: The player who takes the last object wins.
- Misère Play: The player who is forced to take the last object loses.
Most of the time, when people talk about Nim, they mean the "normal play" version where taking the last object makes you win.
An Example Game
Let's look at an example of a normal game of Nim. Imagine two players, Bob and Alice, start with three piles: one with 3 objects, one with 4 objects, and one with 5 objects.
Pile A | Pile B | Pile C | Move |
---|---|---|---|
3 | 4 | 5 | Game begins |
1 | 4 | 5 | Bob takes 2 objects from Pile A |
1 | 4 | 2 | Alice takes 3 objects from Pile C |
1 | 3 | 2 | Bob takes 1 object from Pile B |
1 | 2 | 2 | Alice takes 1 object from Pile B |
0 | 2 | 2 | Bob takes all 1 object from Pile A (leaving two piles of 2) |
0 | 1 | 2 | Alice takes 1 object from Pile B |
0 | 1 | 1 | Bob takes 1 object from Pile C (leaving two piles of 1) |
0 | 0 | 1 | Alice takes 1 object from Pile B |
0 | 0 | 0 | Bob takes the last object from Pile C and wins! |
How to Win at Nim
Nim has a perfect winning strategy based on math! It involves something called the "binary sum" or "nim-sum" of the pile sizes. If you can always leave your opponent with a "nim-sum" of zero, you'll win (in normal play).
The basic idea is to always leave your opponent in a "losing position" (a position where the next player is forced to lose if the other player plays perfectly). If you start in a winning position, you can always make a move to leave your opponent in a losing position. If you start in a losing position, you'll lose if your opponent plays perfectly.
Winning Positions Explained
Here are some examples of "losing positions" (also called "P-positions" for previous player winning, meaning the player whose turn it is now will lose if the other player plays perfectly). If you can always leave your opponent with one of these arrangements of piles, you're on your way to winning!
2 Piles | 3 Piles | 4 Piles |
---|---|---|
1 1 * | 1 1 1 ** | 1 1 1 1 * |
2 2 | 1 2 3 | 1 1 n n |
3 3 | 1 4 5 | 1 2 4 7 |
4 4 | 1 6 7 | 1 2 5 6 |
5 5 | 1 8 9 | 1 3 4 6 |
6 6 | 2 4 6 | 1 3 5 7 |
7 7 | 2 5 7 | 2 3 4 5 |
8 8 | 3 4 7 | 2 3 6 7 |
9 9 | 3 5 6 | 2 3 8 9 |
n n | 4 8 12 | 4 5 6 7 |
4 9 13 | 4 5 8 9 | |
5 8 13 | n n m m | |
5 9 12 | n n n n | |
* This position is only a losing position for normal play (where taking the last object wins). ** This position is only a losing position for misère play (where taking the last object loses). |
In the table, 'n' and 'm' can be any number greater than 0, and they can be the same number.
If you want to get really good at Nim, you can learn about the "nim-sum" and how it uses binary numbers (base-2) to figure out the perfect move every time!
See Also
In Spanish: Nim (juego) para niños