The Sweet Jar
Skill: finding the losing positions, then steering the game into one
Problem
A jar holds 10 sweets. Two players take turns. On your turn you must take 1 or 2 sweets. The player who takes the last sweet wins.
Both players play as well as they possibly can. Who wins, the first player or the second, and what is the winning first move?
Hints
Hint 1
Shrink the game. Work out who wins when the jar starts with 1, then 2, then 3, then 4, then 5, then 6 sweets.
Hint 2
Some starting amounts are hopeless for the player who moves first, because every possible move hands a good position to the opponent. What do those amounts have in common?
Hint 3
If you can always leave your opponent a multiple of 3, you can repeat that forever. Which single first move turns 10 into a multiple of 3?
Solution
Small jars.
With 1 sweet, the first player takes it and wins. With 2, the first player takes both and wins. With 3, the first player must take 1 or 2, leaving 2 or 1, and the second player takes the rest. The first player loses.
The next few.
With 4, take 1 and leave 3, which is a losing amount for the opponent. With 5, take 2 and leave 3. With 6, any move leaves 5 or 4, and both of those are wins for the player about to move, so the player facing 6 loses.
Spot the pattern.
The amounts that lose for the player about to move are 3, 6, 9, 12 and so on: the multiples of 3. Any amount that is not a multiple of 3 is one or two more than a multiple, so the player to move can remove 1 or 2 to leave a multiple of 3.
Apply it to 10.
10 is one more than 9, so the winning first move is to take 1 sweet and leave 9.
Why the strategy keeps working.
From 9, whatever the opponent takes, take the other amount so that the pair of moves removes exactly 3. The jar goes 9, then 6, then 3, then 0, and you take the last sweet. The opponent never gets a turn with a non-multiple of 3.
Answer: the first player wins, by taking 1 sweet first.
Why this works
The multiples of 3 are losing positions: from one, every move hands the opponent a position they can win. Winning play is not about grabbing the most sweets. It is about always handing back a losing position. Finding those positions first, then steering toward them, is the reusable idea in this kind of game.
A jar of 0 is the final losing position, because the player to move has no sweet to take and the previous player has just won. That is why leaving a multiple of 3, rather than taking the most now, is the winning plan.
Try a related problem
The jar now starts with 12 sweets, and the rules are unchanged. Who wins with best play?