sudoku_solver: Solve Sudoku Puzzles

View source: R/sudoku.R

sudoku_solverR Documentation

Solve Sudoku Puzzles

Description

Solve a Sudoku puzzle, where empty values are represented by 0s into a matrix object.

Usage

sudoku_solver(board, needed_cells = NULL, index = 1, quiet = FALSE)

Arguments

board

Matrix. 9x9 matrix or vector length 81, with only digits from 0 to 9.

needed_cells, index

Auxiliary parameters to auto-iterate using this same fx.

quiet

Boolean. Keep quiet? If not, plot results.

Value

Logical output answering of the input board can be solved. The actual solved solution will be created as an object named solved in your .GlobalEnv.

Examples


# board <- c(0,0,0,0,0,6,000,
#            0,9,5,7,0,0,3,0,0,
#            4,0,0,0,9,2,0,0,5,
#            7,6,4,0,0,0,0,0,3,
#            0,0,0,0,0,0,0,0,0,
#            2,0,0,0,0,0,9,7,1,
#            5,0,0,2,1,0,0,0,9,
#            0,0,7,0,0,5,4,8,0,
#            0,0,0,8,0,0,0,0,0)
# sudoku_solver(board)

# Trivial input (everything)
trivial <- matrix(rep(0, 81), byrow = TRUE, ncol = 9)
trivial
sudoku_solver(trivial)

# Wrong / Impossible to solve input
imp <- matrix(c(rep(1, 72), rep(0, 9)), byrow = TRUE, ncol = 9)
imp
sudoku_solver(imp)


lares documentation built on Nov. 5, 2023, 1:09 a.m.