|Nim - and How to Win|
There are two versions of Nim: the one we described where you lose by picking up the last match, and the simpler version where you win by picking up the last match.
The secret of winning at Nim is to realise that there are 'safe' and 'unsafe' patterns. Any move will make a safe pattern unsafe, but only a few of the moves open to a player will make an unsafe pattern safe.
On your turn, you try to make sure that you leave a safe pattern for your opponent to make 'unsafe'. After you have played the game a few times, you will start to recognise the safe patterns.
The starting pattern (1-3-5-7) is a safe pattern. This means that, providing you don't make any mistakes, you will always win if your opponent goes first. You can take turns in starting first or you can give your opponent the choice. Even if you go first, there is a good chance that a novice opponent will make a mistake allowing you to leave them with an 'unsafe' pattern on the next go.
There is a mathematical method for determining which patterns are safe, but most expert players win by remembering a few safe patterns which they aim to achieve. The following are example of safe patterns:
This works all the way through for the simpler version, but for the version where you lose by picking up the last match, you need to change your tactics when all but one of the remaining rows have only one match left (e.g. 1-1-1-4). In this case you need to leave an odd number of one-match rows. For example, if you were left with 1-1-1-4, you would take all the matches for the last row to leave 1-1-1 for your opponent. And if you were left with 1-5-1 would take four matches from the second row.
To determine whether a pattern is safe, first convert the number of matches in each row to a binary number as follows:
1 = 001
2 = 010
3 = 011
4 = 100
5 = 101
6 = 110
7 = 111
So, for the 1-3-5-7 pattern you would get:
Notice that all the columns have an even number of ones. Safe patterns always have an even number of ones in every column.