A LOCK MADE OF A COLOURING · FROM THE KIT
Peg solitaire: a peg jumps over a neighbour into an empty hole and the neighbour is removed. Colour the holes by (r + 2c) mod 3 and again by (2r + c) mod 3; every jump takes one peg of each of two colours and adds one of the third, so the parities of the colour counts move together and their differences never change. Before you waste a move, the board can tell you which end holes a lone peg can ever reach.
pegs – · invariant, colouring A – · colouring B – · a lone peg on the target would read –
Tap a peg, then the hole two away.
Press Ask the invariant.
Green rings mark the holes a lone peg could end on by the invariants; dim ones can never be reached, whatever you do. The red ring is this level's target, which was made by reverse jumps from a lone peg, so a path exists.
Three holes in a line are three different colours under (r + 2c) mod 3, and again under (2r + c) mod 3. A jump from a over b into c removes the pegs at a and b and puts one at c: one colour gains a peg and two lose one, so all three colour counts change parity at once, and the parity of any two counts added together never changes. Each of those parities is a GF(2) weighted sum, SIZones.gfkInvariant(board, 2, weight) with a weight of 1 on two of the three colours; two per colouring, four bits in all. A lone peg at hole h has a definite four-bit reading; if the board's reading differs from it, no sequence of jumps can end there. That is the lock: the invariant says what is inside before you turn the key. (The weighted sum mod 3 itself is not preserved by a jump; the parities are.)
The Invariant · by Lars Rocha · from sitoolz: zones (GF(k) invariants) and indexrng.