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.
Similar Kata:
Stats:
Created | Mar 4, 2018 |
Published | Mar 4, 2018 |
Warriors Trained | 807 |
Total Skips | 138 |
Total Code Submissions | 314 |
Total Times Completed | 80 |
C Completions | 37 |
C++ Completions | 48 |
Total Stars | 33 |
% of votes with a positive feedback rating | 90% of 31 |
Total "Very Satisfied" Votes | 27 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 6 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |