knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
This package is designed to solve any 9 by 9 sudoku grid using the backtracking algorithm.
You can install the development version of sudokur from GitHub with:
devtools::load_all('.')
# install.packages("devtools") devtools::install_github("kennedymwavu/sudokur")
To make your own customized sudoku puzzle which you can view and solve with the functions available in this package, create a 9 by 9 matrix with zeros representing the empty spaces in your sudoku.
Example:
board1 <- matrix( data = c( 5, 6, 0, 8, 4, 7, 0, 0, 0, 3, 0, 9, 0, 0, 0, 6, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 8, 0, 0, 4, 0, 7, 9, 0, 6, 0, 2, 0, 1, 8, 0, 5, 0, 0, 3, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 6, 0, 0, 0, 8, 0, 7, 0, 0, 0, 3, 1, 6, 0, 5, 9 ), ncol = 9 )
To pretty print a sudoku grid use print_board(given_board)
.
Example:
print_board(board1)
To solve a sudoku puzzle solve_sudoku(given_board)
.
Example:
solve_sudoku(samples$board6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.