lights_out_game


lights_out_game, an Octave 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.

The Lights Out game is played on a rectangular board of squares, usually a 5x5 grid, each square containingr a light that may be on or off. Clicking the mouse on a light switches it from on to off and vice versa. However, when you switch a light, you also switch the lights to the immediate left, right, above and below.

You start the game with a randomly chosen configuration of lights and it's up to you to figure out how to get them all out.

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_game is available in a C version and a C++ version and a MATLAB version and an Octave version.

Related Data and Programs:

snakes_game, an Octave code which simulates the game of snakes and ladders.

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 10 November 2024.