Solving Lights-Out Over GF(2): Computing Exact Minimum Par Clicks Across 500 Glass Boards
Lights-Out looks deceptively simple: tap a tile, and it flips itself along with its orthogonal neighbors. Turn all the tiles on (or off) to clear the board.
But if you build a 500-stage Lights-Out game with custom board shapes, locked tiles, and diagonal toggle tiles — like Glass Lights on 2Day Games — two hard questions immediately show up:
- How do you guarantee a board is actually solvable?
- How do you show the player the exact mathematical minimum number of clicks (
Par)?
The answer is one of the cleanest applications of linear algebra in game development: Gaussian elimination over GF(2).
Modeling the Board as a System of Linear Equations
Every tile press is its own inverse — pressing a tile twice is identical to not pressing it at all (1 + 1 = 0 mod 2), and the order of presses does not matter.
That means an N×N board with M active (unlocked) tiles is simply a linear system over the binary field GF(2):
$$A \cdot x = b \pmod 2$$
-
Ais anM×Mbinary toggle matrix whereA[i][j] = 1if pressing tilejflips tilei(easily supporting orthogonal+, diagonal×, or custom patterns). -
bis the target delta vector (1if tileineeds to change state,0otherwise). -
xis the binary solution vector (1= press this tile once,0= leave it alone).
Finding the True Minimum Clicks (Nullspace Search)
Here is the subtle catch many implementations miss: for certain board sizes (famously 5×5 Lights-Out!), the matrix A is not invertible — its nullspace has dimension 2 (4 distinct valid solutions for the same board!).
If you stop at the first solution Gaussian elimination hands you, your Par number might be 11 clicks when a 7-click solution exists!
To compute the exact minimum Par for every stage in Glass Lights:
- Run RREF (Reduced Row Echelon Form) over GF(2) using fast bitmask XOR operations.
- Extract one particular solution
x_0and all nullspace basis vectorsv_1, v_2, ..., v_k. - Iterate over all
2^klinear combinations of the nullspace basis (kis tiny, typically0to4) and pick the solution vector with the minimum Hamming weight (fewest1bits).
That Hamming weight is the mathematically provable minimum Par!
Putting It Into Live Gameplay
In Glass Lights, every stage from 3×3 warmups up to 6×6 boards with locked cells and diagonal tiles carries its pre-verified Par value, displayed live as Clicks N / Par M right above the board.
Give it a try in your browser and see if you can match (or beat your own record toward) mathematical Par:
- Play Glass Lights (500 GF(2)-Verified Stages)
- Explore all 7 browser logic puzzles on 2Day Games