Strategy for solving "Lights Out" puzzle

The method I'm about to explain technically works for any size grid, but it requires some knowledge that I don't know how to determine from scratch. If you want to do some searching online related to it, the method is generally referred to as "chasing lights" or "chasing the lights".

Start by pushing the buttons on the second row corresponding to the lit cells on the top row, then the buttons on the third row corresponding to the lit cells in the second row, etc. This is exactly what you were already doing, chasing the lights down to the bottom row, which is where the name comes from.

Now, as you know, the tricky part comes when you've got a grid that's blank except for the bottom row. At this point, the way to finalize it is to push some specific buttons on the first row corresponding to the lit cells on the bottom row, and then chase the lights down from the top again. If you pushed the right first-row buttons, when you complete the second chase, the puzzle will be solved.

As far as I know, you have to just know which buttons to push on the top row to correspond to a specific pattern that was left on the bottom row after the initial chase. If you can figure out a method of determining the right ones to push on the top, you can probably use a very similar method to generalize this to any size grid. I don't know a method for this though, so I'll, uh, leave that as an exercise to the reader.

For the classic 5x5 version of the puzzle, it turns out that there are only 7 possible patterns on the bottom row after the initial chase down, so I'm just going to list the 7 possible patterns and the corresponding first-row buttons to press for each. Buttons are numbered from left to right.

|--------------------+-----------------|
| Left on bottom row | Push on top row |
|--------------------+-----------------|
| 1, 2, 3            |               2 |
| 1, 2, 4, 5         |               3 |
| 1, 3, 4            |               5 |
| 1, 5               |            1, 2 |
| 2, 3, 5            |               1 |
| 2, 4               |            1, 4 |
| 3, 4, 5            |               4 |
|--------------------+-----------------|

Similar lookup tables can probably be found for the other sizes online.


I don't have a strategy, but here are a few facts about the 5×5 board:

  • Order does not count. Clicking on a tile A, then clicking on a tile B is exactly the same thing as clicking on tile B, then clicking on tile A — or clicking on tile A, then tile B, then tile A again, then again tile A, then maybe flipping some other tile, then tile B.
    In short, a tile either is or is not part of the solution (an unordered set of tiles you must switch). Going in circles trying the same moves over and over again does not get you anywhere.

    1 unlit cell, 11 moves away.
    So close, and yet so far…

  • Less is not more. Attempting to minimize the amount of lit/unlit cells can be counterproductive (see picture above). You should instead try to bring the game to a configuration you can recognise and solve by memory.
  • Symmetric games have symmetric solutions. Keep that in mind: mirror your moves and the game complexity will go down considerably.
  • Solutions are not unique, and the center tile is never required. Although it may make it easier to solve a puzzle, it appears that all solvable games can be solved without the center tile.

The following solution works for every m × n grid:

Think of the given grid as a vector in a m × n dimensional vector space. Every value is either 1 (if the light is on) or 0 (if the light is off). Now you can think of every cell-push as a vector in this vector space. As you can push m x n different cells, you have m x n different vectors. If they change something in a cell, the value is 1, else 0.

As badp mentioned, it is only interesting if you have to push one button or not. No need to look at the order, no need of pushing a button more than once. So you have an equation

vector for your grid = a_1 x cellvector1 + a_2 x cellvector_2 + ... a_mn x cellvector_mn a_1, a_2, ..., a_mn is either 0 or 1.

As you have m x n variables (a_1 ... a_mn) and m x n equations (the rows of the vectors) you can solve it with Gaussian elimination.

If you are German, you might want to read "Aufgabe 2, 30. Bundeswettberwerb Informatik"

Tags:

Lights Out