Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

is_solvable

Is a given Lights Out board solvable?


Description

Not every Lights Out configuration has a solution (this has been mathematically proven). This function determines whether a given board has a solution or not.

Usage

is_solvable(board)

Arguments

board

A lightsout board

Value

TRUE if the given board has a solution; FALSE otherwise.

See Also

Examples

# The following board is solvable using the classic mode (only adjacent lights
# are toggled), but has no solution in the variant mode.
lights <- c(1, 1, 0,
            1, 0, 0,
            0, 0, 0 )
board_classic <- new_board(lights)
board_variant <- new_board(lights, classic = FALSE)
is_solvable(board_classic)
is_solvable(board_variant)

lightsout

Implementation of the 'Lights Out' Puzzle Game

v0.3
MIT + file LICENSE
Authors
Dean Attali [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.