solve_board | R Documentation |
Given a Lights Out board, find the set of lights that need to be pressed in order to solve the board. If no solution is possible, an error is thrown.
solve_board(board)
board |
A |
There are a few algorithms for solving Lights Out puzzles. This function implements the Gaussian Elimination technique, which does not guarantee the minimum number of steps. Therefore, some steps in the given solution may be redundant.
If you are interested, there are many resources online outlining the exact details of how this technique works, and what the other solving strategies are.
A matrix with the same dimensions as the input board, with a 1
in every position that requires a press to solve to the board. Note that the
order of the light presses does not matter.
new_board
random_board
play
is_solvable
is_solved
# Create an empty 5x5 board, press two lights, and then see that the solution
# tells us to press the same lights in order to solve the board.
board <- empty_board(5) %>% play(3, 2) %>% play(4, 1)
board
solution <- solve_board(board)
solution
board <- play(board, matrix = solution)
is_solved(board)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.