Warning! Don't read this unless you really want to know how to beat Nim. Because when you've read it (it's a quite easy algorithm), you will probably not be able to play Nim "normally" again (I sure couldn't once I learned).
The Nim playing field consists of three piles of stones, normally each with between one and nine stones. The two players alternate on taking a number of stones away from one of the piles. The player who takes the last stone loses.
Suppose the playing field looks like this:
Pile | Stones | Amount |
---|---|---|
1 | 5 = 101 | |
2 | 3 = 011 | |
3 | 1 = 001 |
Summing the binary number of stones up yields 101 + 011 + 001 = 113. To make this a number with all even numbers, removing three stones from pile one is a good idea:
Pile | Stones | Amount |
---|---|---|
1 | 2 = 010 | |
2 | 3 = 011 | |
3 | 1 = 001 |
Summing the binary number of stones up yields 010 + 011 + 001 = 022. Your opponent can not get any winning position from this.