Skip to main content
1 of 4
ngm
  • 4.3k
  • 7
  • 29

R, 117 bytes

function(m,p=which(m==8,T))sum(sapply(split(p,1:nrow(p)),function(y)sum(apply(p,1,function(x)all((c(y-x)^2<2)))))==1)

Try it online!

A not-that-great explanation:

f <- function(m) {
  p <- which(m == 8, T)    # Matrix with rows of indices where 8 appears
  sum(
    sapply(
      split(p, 1:nrow(p)), # Split p into a list of its rows
      function(y) {
        # 1 if no neighboring 8s, 0 otherwise
        sum(apply(p, 1, function(x) all((c(y - x)^2 < 2)))) == 1
      }
    )
  )    
}
ngm
  • 4.3k
  • 7
  • 29