R/grid_gen.R

Defines functions grid_gen

Documented in grid_gen

#' grid_gen()
#'
#'This function generates a sudoku grid with a given number for the emty cells
#'
#' @param t The number of the emty cells
#'
#' @return A sudoku grid with \code{t} empty cells
#'
#' @examples Grid_45 = grid_gen(45)
#' @export
grid_gen <- function(t) {
  A <- grid_gen_cplt()
  repeat {
    v <- sample(1:9)
    A[v[sample(1:9, 1)], v[sample(1:9, 1)]] <- NA
    if (sum(is.na(A)) == t) {
      break
    }
  }
  return(A)
}

Try the RSDK package in your browser

Any scripts or data that you put into this service are public.

RSDK documentation built on March 18, 2022, 5:08 p.m.