Lights Out

Pressing a light flips it and its up, down, left and right neighbours. Turn every light off. Stuck? Ask for a hint (one press), or let the solver mark the whole plan. Then try a truly random board: some of those can never be cleared, and the solver will tell you so.

A blue dot means: press this cell.

What's going on

Pressing a cell twice undoes it, and the order of presses does not matter, so a plan is just a set of cells: a column of 0s and 1s. Each press is also a column, recording which lights it flips. Put the press columns side by side and you have a matrix A. Clearing a board b means finding a plan x with Ax = b, where 1 + 1 = 0 because two flips cancel. That is linear algebra mod 2.

The solver runs Gaussian elimination the way you would on paper, except that "subtract a row" is "XOR a row". If the elimination ends with a row saying 0 = 1, no plan exists and the board is impossible. On a 3 × 3 board the matrix is invertible, so every board can be cleared, in exactly one way. On 4 × 4 the matrix has rank 12 out of 16, so only 4096 of the 65 536 boards can be cleared: one in sixteen. On 5 × 5 the rank is 23 out of 25, so one board in four.

"New board" starts from all-off and applies random presses, so it is always solvable. "Random board" lights each cell with a coin flip, and may not be.

Sheet: Lights Out: a puzzle you can prove impossible.