Skip to content

← Math Further 6–8

Who Wins the Race to 20?

Topic 35 · Grades 6–8 · Winning positions

What this builds on from class
  • Grade 6: Whole Number (multiples)
In this unit 7 sections
  1. Try it
  2. What’s going on
  3. Where the rule breaks
  4. Every such game has an answer
  5. Where this is used
  6. Questions
  7. Where to go next

The bus to Bhaktapur is late again, and Asha and Nabin are bored at the stop. Nabin has a game. “We count up from 0, taking turns. On your turn you add 1 or 2 to the total and say the new number. Whoever says 20 wins.”

Asha goes first. “Two.” Nabin: “Three.” Asha: “Five.” Nabin: “Seven.” And so it goes, until Nabin says “Twenty!” They play again, and again, and Nabin keeps winning. When Asha lets him start, he wins then too, and he never seems to think very hard. Is he just lucky?

Play the race yourself against the page. Go first, then let the computer go first. Watch the numbers the computer says: they are colored amber.

Try it

Race to 20

Tap +1 or +2 to add to the total. Whoever says 20 wins. Start a new game with You first or Computer first.

Total 0
You 0 · Computer 0
New game:

Your turn: add 1 or 2 to the total. Whoever says 20 wins.

The computer is choosing its first number…

You said 0. The computer is choosing…

The computer added 0 and said 0. Your turn.

You said 20: you win! Did you have a plan, or were you lucky? Play again and see.

The computer said 20 and wins. Look at the numbers it said (amber). Do you see a pattern?

Guess first. If both players play as well as anyone possibly could, what happens in the race to 20?

Pick an answer to see why.

Try it

Smaller races

A race to 20 is long to think about. Shrink it.

Race to 3. The first player says 1 or 2. Either way, the second player adds what is needed and says 3. So the second player wins.

Race to 4. Now the first player says 1. The second must say 2 or 3, and from either, the first player can say 4. The first player wins.

Here is the table so far, with a few more.

Race to 3 4 5 6 7 8 9 10 11 12
Who wins second first first second first first second first first second
First says 1 2 1 2 1 2

Look at the table. Which races does the second player win?

Pick an answer to see why.

Work backwards from 20

Here is the idea that cracks the whole game. Don’t start at 0: start at the end.

If you say 20, you have won. So 20 is a number you want to say. What about 19? If you say 19, the other player adds 1 and says 20. Bad for you. If you say 18, the other player adds 2 and says 20. Also bad. Now 17. If you say 17, the other player must say 18 or 19, and either way you can then say 20. So 17 is a number you want to say, as good as 20 itself.

Call a number a winning number if the player who says it can go on to win, whatever the other player does, and a losing number if not. Then there are two rules, and they are all you need:

  • A number is winning if every number the other player can say next is losing.
  • A number is losing if the other player can say a winning number next.

Each number’s fate depends only on the numbers just above it. So you can start at 20 and work down, one number at a time, all the way to 0.

Try it

Work the race out backwards

Decide each number, from 19 down to 0. The outlined numbers are the ones the other player could say next. The page checks each answer and says why.

Each turn adds 1 or 2. Whoever says 20 wins, so 20 is a winning number. Now 19: after it, the other player can say the outlined numbers. Is 19 winning or losing?

Right. 20 is a winning number. Next: 19.

Not quite. 20 is a winning number.

Done. Winning numbers: 2, 5, 8, 11, 14, 17, 20. 0 is losing, so the first player wins.

Look at the finished grid. The numbers are in rows of 3, and the winning numbers, 2, 5, 8, 11, 14, 17 and 20, all fall in one column.

And 0? It is the total before anyone has moved, as if the second player had “said” it. It is a losing number: from 0, the first player can say 2, a winning number. That is why the first player wins.

What’s going on

Whatever you add, I add the rest of 3

Why are the winning numbers exactly 3 apart? Suppose you have just said 11. The other player adds 1 or 2: the total is now 12 or 13. Whatever they added, you add the rest of 3: if they added 1, you add 2; if they added 2, you add 1. The total is now 14, exactly 3 more than your last number.

They add You add Together
1 2 3
2 1 3

So once you have said a winning number, you can always say the number 3 above it, and the other player can never land on one: from a winning number, a step of 1 or 2 always lands in between. Counting back from 20 in threes gives 17, 14, 11, 8, 5, 2: the numbers that are 20 minus a multiple of 3. In Grade 6 words: a number is winning when 20 minus it is a multiple of 3.

This is also why the second player wins a race to 3, 6, 9 or 12. For a race to 12, the winning numbers are 12, 9, 6, 3 and 0, and 0 is where the game starts. The first player is already standing on the second player’s winning number, and anything the first player says, the second player answers by adding the rest of 3.

Positions, and working backwards

The totals in the race are its positions, and a winning number is what game theory calls a P-position: P for the previous player, the one who has just moved into it, who wins with best play. A losing number is an N-position: the next player to move can win from it. Working out every position from the end of the game back to its start is called backward induction, or working backwards.

It works for the race because of three things:

  1. The game always ends. The total goes up every turn, so the race to 20 lasts at most 20 turns.
  2. Nothing is left to chance, and both players can see everything.
  3. Every position is either winning or losing. There are no draws.

Wherever those hold, the two rules settle every position, starting from the last ones.

Any race

What if you may add 1, 2 or 3? Then “the rest of 4” works: they add 1, you add 3; they add 2, you add 2; they add 3, you add 1. The winning numbers are 4 apart. With adds of 1 up to k, the winning numbers are (k + 1) apart, counting back from the target. So:

  • if the target is a multiple of k + 1, the second player wins;
  • otherwise the first player wins, by first saying what the target leaves over when divided by k + 1.

Try it

Make your own race

Choose the target and the most you may add. Before you play, work out who should win and what to say first. Then test your plan against the computer.

Total 0
You 0 · Computer 0
New game:
Race to:
Add up to:

Your turn: add 1 to 3 to the total. Whoever says 30 wins.

The computer is choosing its first number…

You said 0. The computer is choosing…

The computer added 0 and said 0. Your turn.

You said 30: you win! Did you have a plan, or were you lucky? Play again and see.

The computer said 30 and wins. Look at the numbers it said (amber). Do you see a pattern?

In a race to 21, adding 1, 2, 3 or 4, what should the first player say?

Pick an answer to see why.

Where the rule breaks

Whoever says 20 loses

Turn the race around: now whoever is forced to say 20 loses. (You still may not pass 20, so a player on 19 has to add 1.)

In the race where saying 20 loses, adding 1 or 2, who wins, and what is the first number to say?

Pick an answer to see why.

Add 1, 3 or 4

So far, the winning numbers have always been one even step apart. Here is a race where they aren’t. On your turn you may add 1, 3 or 4, but not 2, and you may not pass the target. Whoever says 30 wins.

The trick of “the rest of 5” doesn’t work here: if they add 3, the rest of 5 is 2, and you may not add 2. So is there any pattern at all? Work it out backwards and see.

Try it

Add 1, 3 or 4

The same two rules: a number is winning when every number the other player can say next is losing. Here the other player can say the number 1, 3 or 4 above it.

Each turn adds 1, 3 or 4. Whoever says 30 wins, so 30 is a winning number. Now 29: after it, the other player can say the outlined numbers. Is 29 winning or losing?

Right. 30 is a winning number. Next: 29.

Not quite. 30 is a winning number.

Done. Winning numbers: 0, 2, 7, 9, 14, 16, 21, 23, 28, 30. 0 is winning, so the second player wins.

Look at the finished grid, in rows of 7. Which numbers are the winning numbers, and who wins the race to 30?

Pick an answer to see why.

Why must a pattern appear at all? Each number’s fate depends only on the 4 numbers above it, because nobody can add more than 4. So if 4 numbers in a row come out the same as 4 numbers in a row 7 places higher, then the next number down copies the one 7 places higher too, and the next, and so on for ever. Working backwards found the first repeat; after that, the pattern can’t change.

A game where you know who wins, but not how

Here is a stranger twist. A bar of chocolate has its top-left square poisoned. Two players take turns to eat: choose any square that is left, and eat it with every square below it and to its right. Whoever has to eat the poison loses. The game is called Chomp.

Try it

Chomp

Play first, then let the computer go first. The computer never makes a mistake: it has worked out every position of the bar backwards, as you did for the race.

Squares left: 24 You 0 · Computer 0
New game:

Your bite: tap a square to eat it and everything below it and to its right (on a phone, tap again to eat). Never the poison, if you can help it.

The computer is choosing its bite…

The computer ate from row 1, column 1. Your bite.

Only the poison is left, and it is your turn. You have to eat it.

You ate the poison: the computer wins. Who went first? Try again, and look for a first bite that leaves the computer stuck.

The computer had to eat the poison: you win!

Chomp ends (the bar gets smaller every turn), has no luck and no draws. So working backwards settles it, and with 4 rows and 6 columns a computer can do that in a blink: there are only 210 shapes the bar can be eaten into, counting the whole bar and the empty one. But for a big bar there are far too many shapes to work through. And yet, for every rectangle bigger than one square, mathematicians know who wins: the first player. Here is the proof, and it is a famous one.

Suppose the first player starts by eating only the bottom-right square. Either that is a winning move, or it isn’t.

  • If it is, the first player wins.
  • If it isn’t, then the second player has a winning reply: some bite after which the first player can’t win, whatever they do. But every bite takes the bottom-right square too, if it is still there, so that reply would leave exactly the same shape if the first player had made it as the first move. Then the first player could have made it first, and won.

Either way, the first player has a winning first move. This is called a strategy-stealing argument: if the second player had a winning plan, the first player could steal it. But look at what it doesn’t say: it doesn’t tell you which move wins. For a few shapes the winning move is known. On a bar with 2 rows, eat the bottom-right square; on a square bar, eat the square diagonally below-right of the poison, leaving an L with two equal arms. For most rectangles, nobody knows a rule. On the 4 × 6 bar above there is exactly one winning first bite, and the computer found it by searching.

Every such game has an answer

The race, Chomp and noughts and crosses are games in which the players take turns, both see everything, nothing is left to chance, and the game must end. In 1913 the German mathematician Ernst Zermelo published a paper about chess, and the idea now called Zermelo’s theorem is named after it: in such a game, if it cannot end in a draw, one of the two players has a way to win whatever the other does. With draws allowed, either one player can force a win, or both can force at least a draw. Finding out which is called solving the game.

Noughts and crosses is a draw if neither player slips. In 2007 Jonathan Schaeffer’s team at the University of Alberta in Canada showed with computers that checkers (draughts) is a draw too. And in 2009, Lim Yew Jin and Jürg Nievergelt published their proof that Nepal’s own Bagh-Chal is a draw when both sides play perfectly. Chess has not been solved: its positions are far too many to work through.

Where this is used

Questions

In a race to 15, adding 1 or 2, who wins with perfect play?

Pick an answer to see why.

a.★

Race to 20 again, but now you may add 1, 2 or 3. Which are the winning numbers, and who wins?

Answer
b.★

You and a friend play Bachet’s race to 100, adding 1 to 10. You go first. What do you say first, and what numbers do you aim for after that?

Answer

In the race to 100, which most-you-may-add lets the second player win?

Pick an answer to see why.

c.★★

Nabin plays the race to 20 with 1 or 2, and he has just said 9. Asha says 10. What should Nabin say, and why?

Answer
d.★★

In the race where whoever says 20 loses (adding 1 or 2, never passing 20), you go second. Your friend says 2. What do you say, and why does it win?

Answer
e.★★

Chomp on a bar of 2 rows and 6 columns. The first player eats the bottom-right square. Explain how the first player can always win from there.

Hint
Answer
f.★★★

Which numbers, as the most you may add, make the race to 100 a win for the second player?

Hint
Answer
g.★★★

Chomp on a square bar, 5 × 5. The first player eats the square in row 2, column 2, leaving an L: the top row and the left column, 5 squares each, sharing the poison. How does the first player go on to win?

Answer

Where to go next

Where these facts come from
  • Bachet’s problem 19 (Problème XIX), the race to 100 with numbers up to 10, his rule of 11 and the numbers 89 … 1, “whoever starts wins”: Problemes plaisans et delectables, qui se font par les nombres (1612), the 1612 edition on the Internet Archive, pages 99–103, with its Advertissement (120 to reach, numbers up to 8 and up to 9, and the advice not to show the key numbers too early); the same text, modernized, in the 1884 fifth edition by A. Labosne, Problème XXII, pages 115–117 (both public domain; the translation is ours); read October 2026.
  • Bachet’s life (born in Bourg-en-Bresse on 9 October 1581, orphaned at six, Ovid, Académie française 1635 and his gout, died 26 February 1638), his Diophantus of 1621 and Fermat’s marginal note, the 1612 book and its title, and the strategy game among its problems: Heinz Klaus Strick, “Bachet de Méziriac”, MacTutor (translated by John O’Connor, 2022), read October 2026.
  • The “100 game” (add 1 to 10, whoever reaches 100 wins) and the subtraction game with one heap and a limit on each turn: Wikipedia, “Nim”, read October 2026.
  • Chomp’s rules (poisoned top-left square, a bite takes every square below and to the right), David Gale and an earlier equivalent by Frederik Schuh, the strategy-stealing proof, the winning moves on 2-row and square bars, and the size of the search: Wikipedia, “Chomp”, read October 2026.
  • Chomp invented in the early 1970s by David Gale, named by Martin Gardner; no known general strategy for every rectangle: Ivars Peterson, “Chomping to Win”, Science News, 19 March 2003, read October 2026.
  • Zermelo’s 1913 paper on chess and what it is taken to show (with no draws, one player has a winning strategy; in chess, a forced win for one side or a draw for both): Wikipedia, “Zermelo’s theorem (game theory)”, read October 2026.
  • Checkers solved as a draw (Jonathan Schaeffer’s team, University of Alberta, “Checkers Is Solved”, Science, 2007): Wikipedia, “Chinook (computer program)”, read October 2026.
  • Endgame tablebases built by retrograde analysis from checkmate, Thompson’s KQKR used against Walter Browne in 1977, the Lomonosov 7-piece tables (Moscow State University, 2012) and Syzygy’s (2018, 18.4 TB), the mate in 549 moves: Wikipedia, “Endgame tablebase”, read October 2026.
  • Bagh-Chal a draw, its endgame by retrograde analysis (88,260,972 positions inequivalent under symmetry), the placement searched forward: Lim Yew Jin and Jürg Nievergelt, “Tigers and Goats is a draw”, Games of No Chance 3, MSRI Publications 56 (2009), abstract, read October 2026.
  • Every winning number, table, race and answer in this topic (the small races, the rule for any race checked for every target up to 59 and every step up to 11, Bachet’s cases, the race where 20 loses, adds of 1, 3 or 4 with its repeat every 7, the 10,946 races, the questions), and Chomp’s winning first bites and the 210 shapes of the 4 × 6 bar, by search in checks/textbooks/math-further-6-8/35/tmp/numbers.py.