Invariants: Parity
Start with 17 and try to reach 100 by adding 2, adding 4, or subtracting 8. The number can change, but odd stays odd. That unchanging property is an invariant, and it can prove that some targets are impossible.
Junior Olympiad · Intermediate Olympiad · 0 of 5 solved
Flipping neighbouring coins
Can we reach 100?
We start with the number .
At each step we may choose one of three operations:
- add
- add
- subtract
We may repeat them as often as we like, in any order.
Can we ever reach ?
Before reading on, try a few moves yourself. One short path is
The number keeps changing, and we are back where we started. Try a different path if you like. Then look at every number you have reached.
What do they have in common?
They are all odd.
Is that an accident of these particular moves, or does it have to happen?
- We started with an odd number.
- Every allowed operation adds or subtracts an even number.
- An odd number plus an even number is odd. An odd number minus an even number is odd.
So every number we can reach is odd.
But is even.
Reaching is impossible. No sequence of moves, however long, can get there.
We did not have to list every possible path. We found one fact that never changed, and that was enough.
What is an invariant?
The number itself kept changing: became , then , then . Something else did not change at all: whether the number was odd or even.
An invariant is something that stays unchanged, even when other things change.
In this puzzle the invariant is "odd or even". That property has a short name: parity.
Parity is the remainder when you divide by . Even numbers leave remainder . Odd numbers leave remainder . Adding or subtracting an even number cannot change that remainder, so the parity of is an invariant of the puzzle.
Why are invariants useful?
From there are three legal moves. From each new number there are three moves again. After a handful of steps there are already more paths than anyone would want to write down. Checking them one by one cannot settle the question.
An invariant cuts through that. You watch one property, check that every legal move leaves it alone, and compare it with the target.
If the starting parity and the target parity disagree, the target is impossible. That is a proof, not just a failed attempt.
If they agree, the invariant has not decided the question. You still need a sequence of moves that actually reaches the target, or a different invariant.
This is the trick: do not chase every path. Find what cannot change.
Watching a count instead of a number
The same idea works when the changing object is no longer a single number, but a row of coins.
Two coins sit in a row. The first shows tails, the second shows heads. A move flips both coins, because they are neighbours.
Can you reach two heads?
Try it once. Tails and heads become heads and tails. Try it again, and you are back where you started. The coins change, but something feels stuck.
The puzzle taught us to look for a property that never changes. What could that property be here?
Try one more move, but this time ignore which coin is which. Watch only how many tails there are.
- Start: one tail.
- Flip both: the tail becomes a head, and the head becomes a tail. Still one tail.
- Two heads would mean zero tails.
One is odd. Zero is even.
If the number of tails always stays odd, two heads is impossible. With only two coins there is just one kind of move, and we have already checked it: the count of tails does not even change, let alone change by an odd number.
This is the argument again. Before, the number itself stayed odd. Now a count stays odd. The objects look different. The invariant is the same: parity.
Turning two glasses over is the same move under another name. Count the upside-down glasses, and ask whether that count changes by an even number.
How to find an invariant
When a puzzle asks "can I reach this?", try the following.
- Understand what one move does. Write down every type of move, not just the first one you tried.
- Look for something that might stay the same. Often this is a count of "on" objects, or the parity of a sum.
- Check that the property is unchanged by every allowed move. If some move can change it, it is not an invariant.
- Compute the property for the start, and for the position you want.
- If they disagree, the target is impossible. If they agree, the invariant has not finished the job: you still need a sequence of moves, or a stronger invariant.
A useful first question is: does this move change a count by an even number? Changing by , by , or by all leave the parity alone.
An invariant has to survive every legal type of move. One successful (or unsuccessful) attempt is not a proof.
The same idea, a little further
The next two puzzles use the checklist. In each one, try to find the invariant yourself before opening the solution.
The signs , , , are written on a board. A move erases two signs and writes one back: a plus if they were the same, a minus if they were different. One sign remains.
Which sign is it, and why does the order of the moves not matter?
:::
The coins asked "can we reach this?". The signs ask a twin question: whatever order we choose, what must remain? An invariant can answer both.
Four numbers sit in a circle: , , , . A move adds to any two neighbouring numbers. Can some sequence of moves make all four numbers equal?
:::
This is once more. The invariant is again a parity, but now it is the parity of a sum rather than of a single number or of a count of tails.
A circle with more numbers, and a move that adds to two neighbours, is the same test. So is a bag of balls where each move takes two out and puts one back: watch a colour count, and ask whether it changes by an even number.
What an invariant cannot do
A mismatch is a proof of impossibility. A match is not a proof that a path exists.
In the opening puzzle the invariant only forbids even targets. It does not, by itself, prove that a particular odd number can be reached. For that you would still write down a sequence of moves.
Keep the two jobs separate. Use an invariant to show that a target is impossible. Use a sequence of moves to show that a target is possible.
A board coloured in two colours is parity again. Those arguments live in Chessboard colouring. The next remainder, division by , is Invariants: Remainders.
- An invariant is a property that every legal move leaves unchanged.
- Parity — odd or even — is the first invariant to look for.
- If the start and the target have different parities, the target is impossible.
- To find one: see what a move does, look for a count or a sum whose parity never changes, then compare with the target.
- Matching parities do not prove that a position can be reached. For that you still need a sequence of moves.
The problems below are the same test, with coins, signs, glasses, a circle of numbers, and a bag of balls.