lights_out


lights_out, a MATLAB code which analyzes the "Lights Out" game, in which lights on a 5x5 board are randomly lit up. Pushing a light reverses its status, as well as the status of the north, south, east and west neighbor lights. The user seeks to push buttons in such a way that all the lights are turned off.

Only some initial states are actually solvable.

A strategy to solve the game begins by driving all the lighted squares to the bottom row. This is done by starting in the second row, and clicking just below any light in the first row. This blacks out row 1. Repeating this process by working downwards results in turning off all the lights except in the last row.

For the 5x5 case, the strategy then depends on the pattern of lights in the bottom row. Depending on that pattern, click lights ON in the first row, and then repeat the process of driving all the lighted squares to the bottom row. This time, you should end with no lights on.

      if bottom is   start top as

         00111            00010
         01010            01001
         01101            10000
         10001            00011
         10110            00001
         11011            00100
         11100            01000
      
where, of course, "0" means a light is out, and "1" means a light is on.

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

lights_out is available in a MATLAB version.

Related Data and Programs:

lights_out_game, a MATLAB code which sets up the "Lights Out" game, lighting up a few squares on a grid. An interactive user must then try to press squares in such a way that all the lights are turned off.

Reference:

  1. Marlow Anderson, Todd Feil,
    Turning Lights Out With Linear Algebra,
    Mathematics Magazine,
    Volume 71, Number 4, October 1998, pages 300-303.
  2. Oscar Martin-Sanchez,
    Two Analyses of Lights Out,
    Mathematics Magazine,
    Volume 74, Number 4, October 2001, pages 295-304.

Source Code:


Last revised on 12 November 2024.