What are the winning strategies in Nim?
In the game of nim, winning strategies rely on identifying whether a position is "safe" or "unsafe." A position is considered safe if the player who just moved has secured a winning advantage, while an unsafe position allows the next player to potentially take control of the game.1
To determine the status of a position, convert the number of objects in each pile into binary notation. A position is safe if, when you add the digits in each column of the binary representations, every column sums to zero or an even number. If any column sums to an odd number, the position is unsafe.1
The winning strategy is to always make a move that changes an unsafe position into a safe one. By consistently leaving your opponent with a safe position, you maintain control of the game until you can remove the final object. Because this strategy is mathematical, it is possible to program a computer to play a perfect game of nim.1