Nim

Three piles of counters. On your turn, click a counter to take it and every counter to its right in that pile. The computer then does the same. Whoever takes the last counter wins. Try to beat it. Then switch on the secret. (Tick last counter loses for the upside-down version, where taking the last counter loses.)

What's going on

Write each pile size in binary and stack them up. Add each column, but the odd way: write 0 if the column has an even number of 1s and 1 if it has an odd number. This column-by-column "add without carrying" is called XOR, and the result is the Nim-sum.

The whole game rests on one fact. If the Nim-sum is 0 when it is your turn, every move you make leaves a position with Nim-sum not 0. And if the Nim-sum is not 0, there is always a move that makes it 0. The player who keeps handing over a Nim-sum of 0 will take the last counter, because the empty position has Nim-sum 0 and only the loser is ever faced with it.

From 3, 5, 7 the Nim-sum is 1, so the first player can win by taking one counter from any pile. Set the piles to 1, 2, 3 instead, where the Nim-sum is already 0, and the computer will beat you no matter what you do.

Last counter loses. In this mode the Nim-sum rule still decides every position in which some pile has two or more counters. It fails only at the very end: when every remaining pile is a single counter, the player to move wins exactly when there is an even number of them. So the computer plays ordinary Nim until exactly one big pile is left, then cuts that pile to 0 or 1, whichever leaves you an odd number of lone counters.

Sheets: Nim: the game you cannot lose and Nim where the last counter loses.