title: Implement 2d array coordinates in 1d array in C++
body: <p>The code inside the for loop is for the x and y (j and i) "coordinates" from a 2d array. How could I implement this neighbor/index finding in a 1d array?
  I think I could implement it for the first four equations. But i'm confused as how to implement up-left etc.   </p>
  
  <pre><code>for(int i=0; i&lt;cols*rows; i++){
          //Counts current index's 8 neigbour int values
        int count=0;
        int x = i%cols;
        int y = i/rows;
        //rows y i
        //cols x j
  
        count+= [grid][i][(j-1+cols)%cols] //left
           +[grid][i][(j+1+cols)%cols]    //right
           +[grid][(i-1+rows)%rows][j]    //up
           +[grid][(i+1+rows)%rows][j]    //down
           +[grid][(i-1+rows)%rows][ (j-1+cols)%cols]  //up-left
           +[grid][(i+1+rows)%rows][ (j+1+cols)%cols]  //down-right
           +[grid][(i+1+rows)%rows][ (j-1+cols)%cols]  //down-left
           +[grid][(i-1+rows)%rows][ (j+1+cols)%cols] ;//up-right
  }
  </code></pre>