Title: | Sudoku with R |
---|---|
Description: | This is a sudoku game package with a shiny application for playing . |
Authors: | EL KHMISSI Mohamed |
Maintainer: | EL KHMISSI Mohamed <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.1 |
Built: | 2024-11-05 03:42:14 UTC |
Source: | https://github.com/elkhmissi/rsdk |
This function checks if a value already exists in a 3 by 3 box from a sudoku grid
atbox(x, i, j, n)
atbox(x, i, j, n)
x |
A sudoku grid |
i |
An index of a line from the box |
j |
An index of a column from the box |
n |
a value to check its existance in the box that contains the cell of the index (i,j) |
TRUE if the checked value is on the box or FALSE if the checked value is not on the box
atbox(x=grid_gen(49),1,4,8)
atbox(x=grid_gen(49),1,4,8)
This function checks if a value already exists in a column from a sudoku grid
atcol(x, j, n)
atcol(x, j, n)
x |
A sudoku grid |
j |
An index of a column from the grid |
n |
a value to check its existance in the column j |
TRUE if the checked value is on the column or FALSE if the checked value is not on the column
atcol(x=grid_gen(63),1,8) atcol(x=grid_gen(49),7,6)
atcol(x=grid_gen(63),1,8) atcol(x=grid_gen(49),7,6)
This function checks if a value already exists in a row from a sudoku grid
atrow(x, i, n)
atrow(x, i, n)
x |
A sudoku grid |
i |
An index of a row from the grid |
n |
a value to check its existance in the row i |
TRUE if the checked value is on the row or FALSE if the checked value is not on the row
atrow(x=grid_gen(63),1,8) atrow(x=grid_gen(49),7,6)
atrow(x=grid_gen(63),1,8) atrow(x=grid_gen(49),7,6)
This function is a recurcive function that solves a sudoku grid using the backtracking algorithme
bt_solver(x)
bt_solver(x)
x |
A sudoku grid |
A list of two elements in the first one there is the grid x solved as a matrix of 9 by 9, and the second one contains the number of backtracking does R do to solving it.
bt_solver(x=grid_gen(49))
bt_solver(x=grid_gen(49))
This function checks if a 9 by 9 grid is a complete sudoku grid (each number appear only once in its row,column and box )
check_grid(x)
check_grid(x)
x |
A sudoku grid |
True if x is a cpmlete sudoku grid False if x is not
check_grid(x=grid_gen_cplt()) check_grid(x=grid_gen(54))
check_grid(x=grid_gen_cplt()) check_grid(x=grid_gen(54))
This function generates a sudoku grid with a given number for the emty cells
grid_gen(t)
grid_gen(t)
t |
The number of the emty cells |
A sudoku grid with t
empty cells
Grid_45 = grid_gen(45)
Grid_45 = grid_gen(45)
This function generates a complete sudoku grid randomly
grid_gen_cplt()
grid_gen_cplt()
A complete sudoku grid
Grid_complete = grid_gen_cplt()
Grid_complete = grid_gen_cplt()
This function generates a sudoku grid for four levels of playing "Easy", "Difficult","Hard" and "Legend" based
on the number of backtraking does the finction bt_solver
did to solve the grid.
grid_gen_lv(lv)
grid_gen_lv(lv)
lv |
A string argument level for the grid and must be "Easy", "Difficult","Hard" or "Legend" |
A sudoku grid associate to the level in lv
grid_gen_lv("Easy") grid_gen_lv("Legend")
grid_gen_lv("Easy") grid_gen_lv("Legend")
This function checks if it is possible to put a given number in a given empty cell
ispossible(x, i, j, n)
ispossible(x, i, j, n)
x |
A sudoku grid |
i |
The index of the row of the given cell |
j |
The index of the column of the given cell |
n |
The number that we want to check if is possible to put it in the cell of the index (i,j) |
True if it is possible to put n
in the cell (i,j)
ispossible(x=grid_gen_cplt(),4,5,6) ispossible(x=grid_gen_cplt(),4,5,6)
ispossible(x=grid_gen_cplt(),4,5,6) ispossible(x=grid_gen_cplt(),4,5,6)
This function returns the number of possibilities for a given empty cell
nbrposs(x, i, j)
nbrposs(x, i, j)
x |
A sudoku grid |
i |
The index of the row of the given cell |
j |
The index of the column of the given cell |
Number of possibilities for the cell (i,j)
nbrposs(x=grid_gen_cplt(),5,7) nbrposs(x=grid_gen_cplt(),6,9)
nbrposs(x=grid_gen_cplt(),5,7) nbrposs(x=grid_gen_cplt(),6,9)
This function returns an ordred data frame by number of the possibilities for all the empty cells in the grid with index of row for the first column and index of column for the second column and the number of possibilities in third column
order_wposs(x)
order_wposs(x)
x |
A sudoku grid |
data frame
order_wposs(x=grid_gen_cplt())
order_wposs(x=grid_gen_cplt())
This function permutes the columns of a given matrix with a cyclic permutaion
perm_mat(a, v)
perm_mat(a, v)
a |
A matrix |
v |
The length of the cyclic permutation |
A matrix permuted cyclically by v
columns
perm_mat(a=diag(1,5),4)
perm_mat(a=diag(1,5),4)
This function permutes a given vector with a cyclic permutaion
perm_vec(x, i)
perm_vec(x, i)
x |
A vector |
i |
The length of the cyclic permutation |
A vector permuted cyclically by x
values
perm_vec(1:6,4) perm_vec(27:50,15)
perm_vec(1:6,4) perm_vec(27:50,15)
This function plots a given sudoku grid
plt_grid(X)
plt_grid(X)
X |
A sudoku grid |
a plot of the grid
plt_grid(X=grid_gen_cplt())
plt_grid(X=grid_gen_cplt())
This function gives a reactive plot of the grid for the shiny application
plt_grid_play(B, x)
plt_grid_play(B, x)
B |
Initial grid |
x |
The grid that the user put the numbers on it |
a plot of the grid with the user input with a different color red if the input is on the wrong cell and green if the input is on the right cell
This function returns a vector of possibilities for a given empty cell
poss(x, i, j)
poss(x, i, j)
x |
A sudoku grid |
i |
The index of the row of the given cell |
j |
The index of the column of the given cell |
Vector of possibilities for the cell (i,j)
poss(x=grid_gen(46),4,7) poss(x=grid_gen(49),3,9)
poss(x=grid_gen(46),4,7) poss(x=grid_gen(49),3,9)
runSudoku()
runSudoku()
runSudoku()
Opens the sudoku shiny application
This function is a recurcive function that solves a given sudoku grid for shiny application and it is more
optimized than the backtraking solver on the function bt_solver
solver(x)
solver(x)
x |
A sudoku grid |
The grid x
solved
solver(x=grid_gen(46))
solver(x=grid_gen(46))