R/neighbors.R

Defines functions neighbors

neighbors <- function(i, j, nrow, ncol) {
  is <- (i-1):(i+1)
  js <- (j-1):(j+1)
  is <- is[is <= nrow & is != 0]
  js <- js[js <= ncol & js != 0]
  cbind(rep(is, each = length(js)), js)
}

Try the minesweeper package in your browser

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

minesweeper documentation built on April 3, 2025, 9:29 p.m.