Enter pile values to compute the binary XOR, classify the position, and find the heap reduction that moves the nim-sum to zero.
| Sample piles | Binary XOR | Nim-sum | State | Best zero move |
|---|---|---|---|---|
| 3, 4, 5 | 011 XOR 100 XOR 101 | 2 | Winning | Heap 2: 4 to 2 |
| 1, 2, 3 | 001 XOR 010 XOR 011 | 0 | Losing | No zeroing move |
| 7 | 111 | 7 | Winning | Heap 1: 7 to 0 |
| 1, 3, 5, 7 | 001 XOR 011 XOR 101 XOR 111 | 0 | Losing | No zeroing move |
| Decimal heap | 4-bit binary | 8-bit binary | Useful note |
|---|---|---|---|
| 1 | 0001 | 00000001 | Smallest nonzero heap |
| 2 | 0010 | 00000010 | Single second bit |
| 7 | 0111 | 00000111 | Three low bits active |
| 15 | 1111 | 00001111 | All four low bits active |
| 31 | 11111 | 00011111 | Five low bits active |
| Nim-sum result | Position meaning | Move condition | Practical reading |
|---|---|---|---|
| 0 | Losing state | No heap can reduce to zero XOR | The next player needs an error |
| Nonzero | Winning state | Find heap where heap XOR sum is smaller | Reduce that heap only |
| Equals one heap | Often direct clear | Target heap can become zero | Common in one-heap endings |
| High pivot bit | Move is forced by that bit | Choose a heap containing the pivot | Binary rows show the candidate |
| Move formula | Expression | Accept when | Result after move |
|---|---|---|---|
| New heap | heap XOR nim-sum | new heap is lower | Overall XOR becomes 0 |
| Stones removed | heap - new heap | positive whole number | Legal normal nim move |
| Rejected heap | heap XOR nim-sum | new heap is higher | Cannot add stones |
| Losing state | nim-sum = 0 | all candidates rejected | No zeroing move exists |
Nim is a mathematical game that uses pile of matches and has very specific rule for the game. Players can choose any number of matches from a single pile during their turn, but they cant choose matches from more than one pile at a time. The goal of the game is for a player to be the one to take the very last match from the table.
While many people believe that Nim is a game of luck, it is actualy a game that is based upon the concept of binary architecture and mathematical logic. To win the game of Nim, players must understand a mathematical operation known as the nim sum of all of the matches within the piles. The nim sum can be calculated using the mathematical operation known as the XOR operation, or the “exclusive or” operation.
Because Nim is a game that is based upon binary architecture, each of the piles of matches within a game of Nim can be represented as a series of binary bit. If the calculated nim sum of the matches within the piles of matches is 0, then the player whose turn it is will be in a losing state for that game of Nim. If the calculated nim sum is not 0, however, the player whose turn it is is in a winning state for that game of Nim.
To determine whether a player will win a game of Nim or not, players can utilize a tool known as a nim sum calculator. By plugging in the number of matches that are within each of the piles in the game, the nim sum calculator will automatically calculate the nim sum for the game. If the nim sum calculator determines that the state of the game is a winning state for the player who is to move next, then the goal is for that player to make a move that will leave the opponent with a nim sum of 0.
By leaving the opponent with a nim sum of 0, you are placing the opponent into a losing state; they will inevitablly move the nim sum to a non-zero value during their turn, allowing you to move again to 0. To determine which of the piles to reduce to a winning state, players must determine which heap to reduce. Not all heap can be reduced to a winning state; the player must find the binary breakdown of each of the heaps of matches within the game.
Within this binary breakdown, players must find the pivot bit for that game of Nim; the pivot bit is the highest power of two represent within the calculated nim sum. The player must select a heap that contains that pivot bit; it can then be reduced to create a nim sum of 0. Should the player make a move that selects the wrong heap to reduce, they can turn a winning state into a losing state for themself; this will allow their opponent to win the game of Nim.
The starting number of each of the heaps can indicate whether the first player to move in a game of Nim has a winning strategy for that game. For instance, if the heaps contain 3, 4, and 5 matches, the calculated nim sum will not evaluate to 0, indicating that the first player can win the game. However, if the heaps contain 1, 2, and 3 matches, the calculated nim sum will evaluate to 0, indicating that the first player is in a losing state for the game of Nim that has just started.
Thus, if a player is the first to move into a game of Nim, and if the calculated nim sum of the starting piles is 0, then the player will lose the game if there opponent understands how to always keep the nim sum at 0. Beyond the standard game of Nim are variations on the game, such as misere play. In misere play, the goal is for a player to be the one who does NOT take the last match from the table.
The strategy for this variation is almost the same as the strategy for standard play; a player should always strive to keep the nim sum to 0. However, during the endgame of a game of misere play, the strategy change. Instead of wanting to leave the opponent with a heap that contains only heaps of size 1, in this case players must leave an odd number of heap of size 1; this will force the opponent to take the last match of those remaining heaps.
By playing games of Nim and experimenting with different number of matches in each of the heaps, players can develop an understanding of the way in which the binary values relate to the game. When players experiment with different numbers of matches, they will discover, for example, that if there are two piles of the same size of matches, the calculated nim sum will be 0. Should the opponent mirror your move by removing matches from the second pile of the same size as the first, your opponent will be keeping the calculated nim sum to 0.
Thus, your opponent will ensure that you are the one to take the last match from the table. By utilizing a nim sum calculator, players can begin to understand the pattern in each of the binary rows, and to develop the knowledge required to make the correct mathematical move in the game of Nim.
