Chapter 8. Bonus Chapter: Lights Out

This chapter is an optional example application and can be safely skipped.

§8.1 Rules of Lights Out

Here’s Wikipedia’s description, except I replaced 5 with 𝑛:

Lights Out is an electronic game released by Tiger Electronics in 1995. The game consists of an 𝑛×𝑛 grid of lights. When the game starts, a random number or a stored pattern of these lights is switched on. Pressing any of the lights will toggle it and the adjacent lights. The goal of the puzzle is to switch all the lights off.

Here’s a picture of someone playing for 𝑛=5, making two moves:

Figure 7: Illustration of the Lights Out game. (Figure in public domain.)

§8.2 Examples of Lights Out theorems

In this chapter we’ll show that Lights Out is really a linear algebra problem over 𝔽2. As a result, by casting the problem appropriately in linear algebra language, we will be able to prove three theorems:

Theorem 8.1. The number of solvable Lights Out puzzles is always a power of 2, i.e. of the form 2𝑘 for some nonnegative integer 𝑘.
Theorem 8.2. If a Lights Out puzzle is solvable, the number of ways to solve it (ignoring order of moves or repeated moves) is always the same number, namely 2𝑛2−𝑘 (where 2𝑘 is the number of solvable puzzles).
Theorem 8.3. The Lights Out puzzle where every light is on initially is always solvable.

We’ll be able to prove Theorem 8.1 by the end of this chapter. Proving Theorem 8.2 and Theorem 8.3 will need to wait until the end of Chapter 9, at which point we’ll provide exercises to complete those proofs.

These are by no means the only results you can prove about Lights Out. But they give a starting point and a nice showcase of our general theory.

§8.3 Modeling Lights Out using linear algebra

So that we can draw illustrations concretely, we specialize to 𝑛=3. Let’s number the cells of the grid from 1 to 9 as shown in Figure 8 (left). We then consider the nine possible moves, encoding each move as a vector in 𝔽29. For example, selecting the cell marked 1 would toggle the cells 1, 2, 4, so we define the move vector

𝐦1≔⟨1,1,0,1,0,0,0,0,0⟩;

again as in Figure 8 (center and right).

Figure 8: The 3×3 grid with cells numbered 1 to 9. The move 𝐦1≔⟨1,1,0,1,0,0,0,0,0⟩ toggles cells 1, 2, 4.

To really make everything fully explicit, here are all 9 move vectors and their corresponding illustrations, in Figure 9. We’ve written the components of the vectors in three lines in a suggestive way, to make it easier to compare to the image, but you should still think of them as vectors in 𝔽29.

𝐦1≔⟨1,1,0,1,0,0,0,0,0⟩
𝐦2≔⟨1,1,1,0,1,0,0,0,0⟩
𝐦3≔⟨0,1,1,0,0,1,0,0,0⟩
𝐦4≔⟨1,0,0,1,1,0,1,0,0⟩
𝐦5≔⟨0,1,0,1,1,1,0,1,0⟩
𝐦6≔⟨0,0,1,0,1,1,0,0,1⟩
𝐦7≔⟨0,0,0,1,0,0,1,1,0⟩
𝐦8≔⟨0,0,0,0,1,0,1,1,1⟩
𝐦9≔⟨0,0,0,0,0,1,0,1,1⟩
Figure 9: All nine move vectors for 𝑛=3.

Now the punch line is this:

Idea
Solving a Lights Out puzzle is the same as finding 𝐦𝑖 vectors that sum to the given puzzle.

To illustrate, let’s consider the following 3×3 Lights Puzzle:

Figure 10: A 3×3 puzzle with lights 1, 3, 9 on.

We encode the puzzle as a vector as well, in the obvious way:

𝐩≔⟨1,0,1,0,0,0,0,0,1⟩.

Then pressing light 2 corresponds to adding the vector 𝐦2:

𝐩+𝐦2=
⟨1,0,1,0,0,0,0,0,1⟩
+
⟨1,1,1,0,1,0,0,0,0⟩
=
⟨0,1,0,0,1,0,0,0,1⟩.
Figure 11: Selecting cell 2 in the puzzle 𝐩 gives 𝐩+𝐦2.

Now, suppose I tell you that the answer to our 𝐩 in Figure 10 is to press the three lights 2, 3, 6 (in any order). To check this, you would compute

𝐦2+𝐦3+𝐦6=
⟨1,1,1,0,1,0,0,0,0⟩
+
⟨0,1,1,0,0,1,0,0,0⟩
+
⟨0,0,1,0,1,1,0,0,1⟩
=
⟨1,0,1,0,0,0,0,0,1⟩
=𝐩

which when working modulo 2 is equivalent to

𝐩+𝐦2+𝐦3+𝐦6=𝟎

and that’s exactly what we wanted.

Figure 12: Illustration of 𝐩+𝐦2+𝐦3+𝐦6=𝟎.

In summary, solving Lights Out, for any 𝑛, is exactly equivalent to writing the given puzzle as a linear combination of the move vectors 𝐦𝑖.

Proposition 8.4. An 𝑛×𝑛 Lights Out puzzle is solvable if and only if its corresponding 𝔽2𝑛2 vector is in Span(𝐦1,…,𝐦𝑛2).

At this point, the first advertised theorem, Theorem 8.1, is complete:

Exercise 8.5. Combine Proposition 8.4 with Proposition 7.4 to conclude Theorem 8.1.

§8.4 Every 3×3 Lights Out puzzles has a unique solution

In this section, we will still only focus on 𝑛=3, but these results do not generalize to all 𝑛. Our goal is to prove:

Proposition 8.6. On a 3×3 board, every Lights Out puzzle has a unique solution.

The basic strategy of the proof is to show that 𝐦𝑖 are spanning in 𝔽29. Then we can apply Proposition 3.17 to conclude 𝐦𝑖 are a basis, and then we’re done.

Exercise 8.7. Solve the puzzle when only one edge light is on (e.g., light 2).

Exercise 8.8. Consider any vector with exactly one 1 (i.e. a standard basis vector for 𝔽29). Show that it’s in the span of the move vectors, by considering three cases:

Conclude that 𝐦1, …, 𝐦9 are indeed spanning.

Exercise 8.9. Finish the proof of Proposition 8.6.

§8.5 How to beat the 1995 video game

TODO. write this

§8.6 Exercises

Exercise 8.10. Prove that every possible 2×2 Lights Out has a unique solution, by showing that the 4 move vectors form a basis.

Exercise 8.11. We will work on 4×4 Lights Out puzzles.