←back to thread

82 points raymondtana | 2 comments | | HN request time: 0.001s | source

"Lights Out" is a mathematical puzzle that lives on an grid where each cell of the grid is one of two colors: either red or white. The goal is to eventually get all the cells in the grid to be red.

What's the catch? Clicking a cell will not only flip its color, but also that of all cells sharing the same row or column as it.

To me, this game feels like playing with a Rubik's cube --- every time you think you are fixing one cell, you mess up its neighbors!

There are many ways to arrive at a solution... some mathematical (linear algebra, or combinatorics), others more logical,... and yet others which are brute force.

The title “Lights Out” comes from a classic handheld game from 1997. The “rule” they follow for which-cells-get-flipped-on-click is what I call “Adjacent.” Additionally, my mathematics teacher showed me this game following another variant which I call “Same Row & Column,” but on a bigger board. He had worked out an algorithm for his version. I found the same strategy before he revealed the answer, and I feel that the process of discovering a solution is quite rewarding—it’s fundamentally related to computing on restrictive computer architectures.

I implemented this app with pretty basic TypeScript. It’s been used for some experiments to discover more general of strategies for different click variants, board sizes, and even board dimensions! It has also been the basis for the corresponding video produced using the Python library manim.

Try it out and let me know how you do!

Show context
raymondtana ◴[] No.45545467[source]
Hi everyone, I'm the OP and wanted to share a few comments that might come as spoilers. So read with caution!

1. The default game has a simple winning strategy: the app begins with a 5x5 board under the "Same Row & Column" variant. Some here have already figured out how to get all reds: [Memorize all the white squares on the board at some fixed moment, and click those cells in any order.] Some of the info below helps see why.

2. The game is always winnable: the app is set up to secretly begin with all reds and then perform many random clicks to mess it up; it's always reversible.

3. The order of clicks doesn't matter: the click actions commute.

4. Every click is self-inverse: clicking a cell twice under any variant leads to the same board as before.

5. A winning strategy need only list out which cells to click once: Because of the properties of commutativity and self-inverse, any winning strategy could be freely shuffled in order and have any duplicate clicks cancel out, leading to a strategy of cells meant to be clicked just once---the rest ignored.

6. Suppose "n" is odd and play the "Same Row & Column" variant. Then, the n-by-n board is solvable by the strategy of "click all the cells that were white." But when "n" is even, then this strategy fails on the n-by-n board. However, there indeed is another strategy that solves those systematically.

7. Very little is known about the other variants, nor about other sizes and dimensions of boards. And it is not true in general that any random pattern of white-and-red can be turned into all-reds. Try to find a good heuristic for separating out winnable vs. unwinnable boards!

8. I did forget to mention other versions of Lights Out besides the handheld game. Other physical games and video games used the 5x5 "Adjacent" variant, too.

Bonus Questions:

1. Can you think of an interesting clicking-rule variant that would not be commutative?

2. Can you come up with the winning strategy for winning n-by-n boards when n is even under the "Same Row & Column" variant?

3. Can you figure out any winning strategy for the other variants? I haven't found any good way to proceed without just memorizing the solutions.

Thanks for the comments!

replies(1): >>45547605 #
1. rossant ◴[] No.45547605[source]
Among the 2^n configurations, how many are solvable?
replies(1): >>45572733 #
2. raymondtana ◴[] No.45572733[source]
In the n-by-n case when n is even, all of them are possible :)

In the n-by-n case when n is odd , that's not the case... it breaks into a few equivalence classes that you can separate out by looking at the "mod 2 sums" across each of the rows and columns.