6 kyu

Solve a 3×3 Lights Out game

Description:

You have a grid of size 3×3. Each cell has a binary state: namely, it can be either lit or unlit. Each cell can also be pressed: by doing so, one flips the states of the cell that was pressed, and the states of every cell that's up, down, right, or left of the pressed one. An interactive version can be found here:

http://bz.var.ru/comp/web/js/floor.html

This kind of puzzle is called "Lights Out", after a popular (5×5) handheld game in the 90's.

You are given a function (press_button) that accepts two numbers that correspond to the pressed button's coordinates, and outputs the new state as an array of booleans. For instance, if you have the state {0, 1, 1, 1, 1, 0, 0, 1, 0} and you press the upper-left button, it changes as follows:

░░████      ██░░██
████░░  ->  ░░██░░
░░██░░      ░░██░░

Your task is to create a function that can solve a randomised 3×3 Lights Out puzzle. The function should accept the pattern of lights that are already on (please refer to example code for the exact format in each language) and output the pattern of buttons that have to be pressed in order to turn every light on at once. Since no button has to be pressed more than once, it is enough to output a boolean-type for each button that has to be pressed.

Hint: For our case, every possible pattern is solvable, and every solution is unique.

Puzzles
Games
Algorithms

Stats:

CreatedMar 4, 2018
PublishedMar 4, 2018
Warriors Trained807
Total Skips138
Total Code Submissions314
Total Times Completed80
C Completions37
C++ Completions48
Total Stars33
% of votes with a positive feedback rating90% of 31
Total "Very Satisfied" Votes27
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes2
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Master_Prichter Avatar
  • siebenschlaefer Avatar
  • user9644768 Avatar
Ad