Take turns removing stones. Whoever takes the last stone loses.
Starting piles
Rule
Who goes first
Computer plays
Play a few games first and look for a pattern. When you're ready, check “Show the secret” above the board.
Charles Bouton, a Harvard mathematician, published the complete strategy in 1901 and gave the game its name. At the 1940 New York World's Fair, a machine called the Nimatron played thousands of visitors and won about nine times out of ten. In the 1961 film Last Year at Marienbad, a character keeps winning with rows of 1, 3, 5 and 7 under the last-to-take-loses rule.
The binary trick reaches far beyond this game. In the 1930s, Roland Sprague and Patrick Grundy proved that every game where both players have the same moves and the last player to move wins behaves exactly like a single pile of Nim of some size.