PuzzleReels
Sections

Chomp

The maths · Episode 18 · 3:12 · gives the answer

The puzzle

A bar of chocolate is 6 squares tall and 8 wide. The square in the bottom-left corner is poisoned.

Two players take turns. On your turn you pick one square and bite: you eat that square and every square above it and to its right. Whoever has to eat the poisoned square loses.

Who wins with perfect play, the player who goes first or the player who goes second?

Before
Pick the square at row 3, column 6. The bite takes it and everything above and to the right of it: the 12 pale squares.
After
36 squares are left. The rows, from the bottom up, are 8, 8, 5, 5, 5, 5 squares long.

The poison is the navy square with the skull. Rows are counted from the bottom and columns from the left, so the poison is row 1, column 1.

A bite takes everything above and to the right of the square you pick, so what is left always gets shorter as it goes up, never longer. We call what is left a position, and we write it as the length of each row from the bottom up. The full bar is 8, 8, 8, 8, 8, 8. After the bite above, the position is 8, 8, 5, 5, 5, 5.

The answer

There are two proofs below. The first is a search a computer can do for any bar of reasonable size. The second is a short argument that covers every bar at once, and it never finds the winning bite. Both start from one idea.

Winning and losing positions

A position is winning if the player about to move can force a win, whatever the other player does. It is losing if the other player can force a win instead. Here is why every position is exactly one of the two, working backwards from the end of the game.

  1. The game ends when someone eats the poison, which leaves the empty position. The player who now has to move has won, so we call the empty position winning.
  2. Take any other position, and suppose we have already labelled every position with fewer squares. Every move eats at least one square, so every move leads to a position we have labelled.
  3. If some move leads to a losing position, this position is winning: make that move and the other player is stuck.
  4. If no move does, every move hands the other player a winning position, so this position is losing.

Every position gets one label, and the labels mean what they say. From a winning position, move to a losing one. Your opponent can only answer by moving to a winning one, and you move to a losing one again. Each move eats a square, so this ends, and you never eat the poison, because the empty position is winning, not losing. So the other player does. Nobody can force a draw.

Here are the four smallest positions with a poison in them, labelled this way:

1. The poison alone
The only move eats the poison.
losing for the player to move
2. A square beside the poison
Bite the green-ringed square and the other player is left with the poison.
winning for the player to move
3. A square above the poison
Bite the green-ringed square: the same trick.
winning for the player to move
4. One square on each side
Every bite leaves a winning position for the other player, or eats the poison.
losing for the player to move

This is the fact the steal needs: the full bar is either winning or losing for the first player, and if it is losing, the second player wins.

Now do the same for every position of a 3 × 3 bar. The positions are grouped by how many squares are left, and coloured in that order, fewest squares first.

1 square
2 squares
3 squares
4 squares
5 squares
6 squares
7 squares
8 squares
9 squares
winning for the player to movelosing for the player to move

The empty position is the twentieth, and it counts as winning. Of the other 19, 5 are losing: 1; 2,1; 2,2,1; 3,1,1; 3,2. Every other position has a bite that leads to one of those five. The full 3 × 3 bar is winning, and its winning bite leaves 3, 1, 1.

Play a few games

Click a square to bite. The page tells you whether the position you leave is winning or losing for whoever moves next. You move first against a computer that knows the whole table. Show the winning bites if you want to see where they are.

BarWinning first biteLeaves
2 × 3row 2, column 33, 2
3 × 3row 2, column 23, 1, 1
4 × 5row 3, column 35, 5, 2, 2
5 × 5row 2, column 25, 1, 1, 1, 1
6 × 8row 3, column 48, 8, 3, 3, 3, 3

The backwards labelling above is a program. Label the positions with one square, then with two, and so on up to the full bar. The film does this for a 2 × 3 bar, which has 10 positions. The verifier does it for every bar up to 9 × 9 and finds that the first player wins every one except 1 × 1.

How many positions? Follow the outline of a position from the top-left corner to the bottom-right. It is m steps down and n steps right in some order, and every order is a different position, so an m×n bar has

(m+nm)

of them. Every one can be reached by biting, working from the top row down. A 3 × 3 bar has 20, a 5 × 5 bar 252, and the 6 × 8 bar 3003, of which 142 are losing. A computer settles that in an instant.

A 100 × 100 bar has (200100) positions. That is a number with 59 digits, about 9.05×1058. No computer will ever search that.

So the search settles the bars on its list and says nothing about any other bar. It also gives only a table, never a rule. The second proof covers every bar.

Proof two: steal the strategy

The idea is to suppose the second player wins, and to show that the first player could have copied his strategy. That is a contradiction, so the second player cannot win.

Take any rectangular bar B with at least two squares, and suppose the second player wins. Then B is a losing position for the first player. The pictures use the 4 × 5 bar. There the second player really does have a winning reply, which is what makes the theft work.

1. The whole bar
The ringed square is the top-right one. Call it T. It is not the poison.
2. The first player eats only T
Now the second player is to move. Suppose he can win from here.
3. His winning reply, X
He bites row 3, column 3. That eats 5 squares.
4. The first player plays X himself, straight away
On the full bar the same bite eats 6 squares: those 5 and T, since T is above and to the right of every square.
5. Both ways end here
The same position either way. The first player has reached it, and it is the other player's turn.
losing for the player to move
  1. The first player eats only the top-right square, T. It is not the poison, because B has more than one square.
  2. The second player must have a winning reply. We supposed B is losing, so every first bite leaves a winning position for the player who moves next. In particular this one does. So the second player has a bite X that leaves a losing position for the first player.
  3. The first player could play X straight away. Every bite takes the top-right square, because that square is above and to the right of every square on the bar. So X, played on the full bar, eats exactly what "T, then X" eats: the squares of X, plus T, which was going to be gone anyway.
  4. So the first player reaches the same position. That position is losing for the player who moves next, and now that is the second player. So B has a move to a losing position, which means B is winning for the first player. That contradicts our supposition.

So B is winning for the first player. On the 1 × 1 bar, step 1 fails: the top-right square is the poison.

On the 4 × 5 bar the second player's reply to the corner bite is the bite at row 3, column 3. It eats 5 squares after the corner has gone, and 6 on the full bar. Either way what is left is 5, 5, 2, 2, a loss for the player to move.

Why the corner is the whole trick. The steal works because every bite contains T. If a bite could leave T standing, then X on the full bar would leave one square more than "T, then X", and nothing would follow. That is why this is about rectangles. A staircase with several outer corners has no square that every bite must take.

What the proofs do not tell you

The first proof is a table, and the second only says that a winning bite exists. Neither gives a rule for a bar nobody has tabulated. The steal even avoids naming X: it says a winning reply to the corner bite could have been played first, and if there is no such reply, the corner bite itself wins.

For two kinds of bar there is a rule, and it is short. For three rows nobody has one.

Optional: bars that do have a rule

Nothing later depends on this section.

5 × 5
Bite row 2, column 2, next to the poison.
An L
Two arms of 4 squares.
losing for the player to move
2 × 5
Bite the top-right square.
Two rows
The top row is one square shorter.
losing for the player to move

Square bars: leave an L, then mirror

On an n×n bar with n≥2, bite the square diagonally next to the poison, at row 2, column 2. That leaves an L: the poison, with n−1 squares up the left edge and n−1 along the bottom. For a 4 × 4 bar that is 4, 1, 1, 1, and for a 5 × 5 bar 5, 1, 1, 1, 1.

An L with two arms of the same length is losing for the player to move. Whatever he bites, one arm gets shorter (or he eats the poison and loses at once). Cut the other arm to the same length, and the L is equal again and shorter. Repeat, and the arms run out first for him. Formally this is induction on the arm length a: for a=0 only the poison is left, and every move from an equal L has an answer that leaves a smaller equal L.

1. Equal arms
Whatever the player to move does, one arm gets shorter. Say he bites the left arm down to 2.
losing for the player to move
2. The arms are now 4 and 2
Cut the longer arm down to 2.
winning for the player to move
3. Equal arms again
Now it is the other player's problem, with a shorter L.
losing for the player to move

So the first player wins every square bar by leaving the L and then mirroring. The verifier finds that for every square up to 9 × 9 this is the only winning first bite.

Two rows: leave the top row one shorter

On a 2 × n bar, bite the top-right square. The bottom row has n squares and the top row n−1. Write Sa for the position with a bottom row of a squares and a top row of a−1. The film's 2 × 3 and 2 × 5 bars leave 3, 2 and 5, 4.

Sa is losing for the player to move, for every a≥1. Induct on a. S1 is the poison alone. For a≥2, take any move that is not the poison:

  • A bite in the top row at column c (counted from 0 at the poison) leaves the bottom row at a and the top row at c. Answer with a bite in the bottom row at column c+1. That leaves Sc+1, a smaller one.
  • A bite in the bottom row at column c≥1 leaves both rows at length c. Answer by biting the top-right square. That leaves Sc, a smaller one.

Either way the answer leaves a smaller S, so every move from Sa is answered. The verifier finds that the corner bite leaves n, n-1 as a losing position for every n up to 30, and that it is the only winning bite up to n=9.

Three rows: no rule known

Here are the winning first bites for 3×n, found by the search:

3 × 3
Bite row 2, column 2. That leaves 3, 1, 1.
3 × 4
Bite row 2, column 3. That leaves 4, 2, 2.
3 × 5
Bite row 3, column 4. That leaves 5, 5, 3.
3 × 6
Bite row 2, column 4. That leaves 6, 3, 3.
3 × 7
Bite row 3, column 5. That leaves 7, 7, 4.
3 × 8
Bite row 2, column 5. That leaves 8, 4, 4.
3 × 9
Bite row 3, column 7. That leaves 9, 9, 6.

Each is the only winning bite on its bar. The even n shown, and n=3, leave two equal short rows, and the odd n from 5 do not. This is a table up to n=9, not a theorem about all n. The film says no formula is known, and this page does not claim there is none.

What the steal cannot do

The steal works on rectangles. A position that is not a rectangle can be losing for the player to move. The 3 × 3 map has several, and 3, 1, 1 is one. The theorem also holds for m×n and n×m together, since they are the same game turned on its side, and the verifier checks that the two orientations agree.

In the film

The film plays a 4 × 6 bar for 7 moves. The first player always bites something that does not win, and the other player always finds the winning reply. Near the end the position is 1, 1, the poison and the square above it. The second player takes the square above, and the first player is left with the poison alone.

The bite at the top of this page is the first of the film's three demonstration bites on the 6 × 8 bar, at row 3, column 6; row 5, column 4; and row 2, column 7. It eats a block 4 squares tall and 3 wide, 12 squares in one piece.

Checking it

scripts/chomp.mjs writes the numbers on this page and asserts them first.

Every bar up to 9 × 9. It solves all 81 bars by search and asserts that the first player wins every one except 1 × 1. It counts the positions reached from each bar and asserts the count is exactly (m+nm).

The winning bites. The bites quoted for 2 × 3, 2 × 5, 3 × 3, 4 × 4, 5 × 5 and 3 × 5 are exactly the winning bites found. For squares and for 2 × n up to n=9 the winning bite is unique. The corner bite leaves the lost position (n,n−1) for 2 × n up to n=30, and the equal L is lost for every square up to 9 × 9.

The steal, step by step. For every bar bigger than 1 × 1 up to 9 × 9, and every possible reply X to the corner bite, 1944 in all, the script asserts that X is a legal bite on the full bar, that its rectangle contains the corner, and that X on the full bar gives exactly the position "corner, then X". It also checks the conclusion on each bar.

The playable bar and the diagrams. The page draws every diagram, and plays the game above, with one piece of code, site/lib/chomp-core.mjs. The script checks that code against its own solver on all 48,620 positions of the 9 × 9 bar: who wins, every move, every bite, and the computer's reply. It checks that the copy pasted into this page is the same. Each diagram is built in the script from those positions. For each one, the squares drawn as eaten are exactly what the bite eats, the colour is the solver's, and the number of squares drawn is the right number. A wrong diagram stops the build.

What is not checked. The proofs on this page are for every bar. The script tests bars up to 9 × 9, and goes further for the 2 × n corner. That Chomp has been studied since 1974, and that no efficient algorithm for general m×n bars is known, are claims about the literature, and the script does not assert them.

Where this shows up

  • The history. The game is credited to David Gale, in 1974. An older game played on the divisors of a number is the same game in different clothes. The script does not check either.
  • Strategy stealing is a standard device in game theory. It shows that the first player wins Hex on an empty board, and that the second player can never win a game of the tic-tac-toe family. In each, as here, it says who wins without saying how.
  • Existence without construction. Plenty of results say that something is there without giving it. Chomp is a clean example: the thing that exists is a move on a board anyone can draw.

Try it yourself

1. Why does the steal fail on a 1 × 1 bar?

The corner is the poison. The first step, bite only the top-right square, is eating the poison, which loses at once. And the conclusion is false: the first player has one move, and it loses.

2. On an L with arms of length 4 and 2, what should the player to move do?

Bite the long arm down to length 2. That leaves an equal L, which is losing for the player who must move.

3. Use the formula to count the positions of a 3 × 3 bar, and check it against the page.

(63)=6·5·43·2·1=20, and the verifier's count is 20. The same formula gives (52)=10 for the 2 × 3 bar, the 10 positions of the film's tree.

4. On a 2 × 2 bar, which bite should the first player make, and what does the other player face?

The top-right square. That leaves 2, 1, the last of the four small positions above, which is losing. If the second player bites the square above the poison, the bottom row of two is left, and the answer is to bite its right-hand square, which leaves the poison alone. If he bites the right-hand square instead, the poison and the square above it are left, and the answer is to take that square. Either way the second player is left with the poison.