I have n*n grid, where for example n=10. I have to fill it with black and white elements. Every black element has to have one, two or three black neighbors. It is not allowed to contain black elements with four or zero neighbors.
How should I build this kind of grid ?
Edit:
To be more specific, it is two-dimensional array built for example with two for loops:
n = 10
array = [][];
for ( x = 0; x < n; x++ ) {
for ( y = 0; y < n; y++ ) {
array[x][y] = rand(black/white)
}
}
This pseudo code builds somethind like:

And what I expect is:

Obviously, you’re trying to generate “black path” shapes on a write grid.
So let’s just do it.