Solving “Large” Lights-Out Puzzles With Python
The Lights-Out Puzzle
The lights-out puzzle is pervasive in video games. The premise is simple: you start with a grid of lights each with a switch to turn them on/off. Some lights are on and others are off. The goal is to turn all lights off. The catch? Whenever you flip the switch for any given light, the state (on/off) of the 4 adjacent lights (think above, below, left, and right) is also toggled.
Solving 3 x 3 puzzles is not difficult. Here’s one way in which you can turn lights off starting from a configuration where only the center light is on:
Things become a little more complex when dealing with larger puzzles. How would you turn all lights off starting from the next configuration:
A more generalized variant of the lights-out puzzle asks the question: given a starting…