x1 <- x
x2 <- x-x
repeat{
p <- which(x1==1, arr.ind = T)
for(i in 1:nrow(p)){
x2[p[i,,drop=F]]=as.numeric(sum(x1[(p[i,1]-1):(p[i,1]+1),(p[i,2]-1):(p[i,2]+1)])>4)}
if(sum(x1)==sum(x2)){break()}
x1 <- x2
x2 <- x2-x2}
sum(x)-sum(x1)
x1 <- x
x2 <- x-x
repeat{
p <- which(x1==1, arr.ind = T)
for(i in 1:nrow(p)){
x2[p[i,,drop=F]]=as.numeric(sum(x1[(p[i,1]-1):(p[i,1]+1),(p[i,2]-1):(p[i,2]+1)])>4)}
if(sum(x1)==sum(x2)){break()}
x1 <- x2
x2 <- x2-x2}
sum(x)-sum(x1)
input_d4 |> read_lines()|> str_split("",simplify=T)
x <- x=="@"
x=cbind(rep(0,nrow(x)),x,rep(0,nrow(x)))
x=rbind(rep(0,ncol(x)),x,rep(0,ncol(x)))
p <- which(x==1, arr.ind = T)
tot <- 0
for(i in 1:nrow(p)){
tot <- tot+(sum(x[(p[i,1]-1):(p[i,1]+1),(p[i,2]-1):(p[i,2]+1)])<5)}
tot
input_d4 |> read_lines()|> str_split("",simplify=T)
x <- x=="@"
x=cbind(rep(0,nrow(x)),x,rep(0,nrow(x)))
x=rbind(rep(0,ncol(x)),x,rep(0,ncol(x)))
p <- which(x==1, arr.ind = T)
tot <- 0
for(i in 1:nrow(p)){
tot <- tot+(sum(x[(p[i,1]-1):(p[i,1]+1),(p[i,2]-1):(p[i,2]+1)])<5)}
tot
onlinelibrary.wiley.com/doi/epdf/10....
onlinelibrary.wiley.com/doi/epdf/10....