Emzini weCodeUmhlahlandlelaMathematics 15.8 · Sets, Logic and Counting NoticesAll books

Chapter 15/15.8Accelerateabout 7 min

Parity, invariants and games

Try this first

Nine coins lie on a table, all heads up. A move is to turn over exactly two coins. Can you reach all tails? Try with real coins before reading on.

Recall from Chapter 1 that an invariant is a quantity that does not change, and from Chapter 3 that parity means odd or even. Together they prove that some things are impossible.

Worked example 15.7

Show that the nine coins can never all be tails.

Watch the number of heads.
Turning two heads changes it by −2, two tails by +2, and one of each by 0.
So it always changes by an even number, and its parity is an invariant.
It starts at 9, which is odd, so it is always odd.
All tails would mean 0 heads, which is even.
So it can never happen.

Now try one yourself

Worked example 15.8

Three frogs sit on the dots (0, 0), (1, 0) and (0, 1) of a grid. A frog may jump over another frog and land the same distance beyond it, so a frog at P jumping over a frog at Q lands at the point twice as far from P as Q is. Can a frog ever reach (1, 1)?

A frog at (a, b) jumping over a frog at (c, d) lands at (2c − a, 2d − b).
Since 2c is even, 2c − a is odd exactly when a is odd, and the same holds for the second coordinate.
So each frog keeps the parity of both its coordinates for ever.
The frogs start with parities (even, even), (odd, even) and (even, odd).
The point (1, 1) is (odd, odd), so no frog can ever reach it.

Now try one yourself

Games and working backwards. In Chapter 3, Sipho and Nomsa took 1 or 2 stones, and the multiples of 3 were losing positions. Now go one step further. A losing position is one where every move leads to a winning position for the opponent. A winning position is one with at least one move to a losing position. Starting from 0 stones, which is losing for the player to move, label positions one at a time.

Worked example 15.9

Players take turns to remove 1, 3 or 4 stones from a pile. Whoever takes the last stone wins. Find the losing positions. With 20 stones, who wins, and how?

0 is losing.
1, 3 and 4 are winning (take everything).
2 is losing: its only move is to 1, a winning position.
5 can move to 2, so it is winning, and so is 6 (move to 2).
7 moves only to 6, 4 and 3, all winning, so 7 is losing.
Continuing, the losing positions are 0, 2, 7, 9, 14, 16, 21, 23, ...: the numbers that leave remainder 0 or 2 on division by 7.
20 leaves remainder 6, so the first player wins by taking 4, leaving 16.
From a losing position every move leads to a winning one, and the winner always has a reply that returns to a losing position.

Now try one yourself

Take 1, 3 or 4 stones: winning and losing positionsWork backwards from 0. A position is red if every move from it reaches teal, and tealif one move reaches red.1A PILE OF 20 STONESTwo players take turns.Each turn, take 1, 3 or 4 stones.Whoever takes the last stone wins.2STONES LEFT FOR THE PLAYER ABOUT TO MOVE0losing1winning2losing3winning4winning5winning6winning7losing8winning9losing10winning11winning12winning13winning14losing15winning16losing17winning18winning19winning20winninglosing for the player to movewinning3WHY 7 IS A LOSING POSITION7losing6winningtake 14winningtake 33winningtake 4Every move from 7 leaves a winning position for the other player, so 7 is losing.
Figure 15.6 Red positions lose for the player about to move; from every teal position there is a move to a red one.

Check your understanding 15.8

  1. In the coin game with 9 coins, a move now turns over exactly three coins. Can all nine end tails? Explain.
    Show answerHide answer
    Yes. Each move changes the number of heads by an odd number (−3, −1, +1 or +3), so parity no longer stays fixed. For example, turn coins 1, 2, 3, then 4, 5, 6, then 7, 8, 9: all tails after three moves.
  2. The numbers 1, 2, ..., 9 are written on a board. A move replaces two numbers by their sum. Is the last number odd or even?
    Show answerHide answer
    Odd. The sum of all the numbers never changes, so the last number is 1 + 2 + ... + 9 = 45.
  3. In the 1, 3 or 4 game, is 30 a winning or losing position? If winning, what should you take?
    Show answerHide answer
    30 leaves remainder 2 on division by 7, so it is a losing position.