title: Generate paths on n*n grid
body: <p>I have <code>n*n</code> grid, where for example <code>n=10</code>. 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.</p>
  
  <p>How should I build this kind of grid ?</p>
  
  <p>Edit:</p>
  
  <p>To be more specific, it is two-dimensional array built for example with two <code>for</code> loops:</p>
  
  <pre><code>n = 10
  array = [][];
  for ( x = 0; x &lt; n; x++ ) {
      for ( y = 0; y &lt; n; y++ ) {
          array[x][y] = rand(black/white)
      }
  }
  </code></pre>
  
  <p>This pseudo code builds somethind like:</p>
  
  <p><img src="https://i.stack.imgur.com/wM93A.png" alt="current"></p>
  
  <p>And what I expect is:</p>
  
  <p><img src="https://i.stack.imgur.com/8BWS2.png" alt="expected"></p>