title: How to solve 8 queens 1D array with brute force?
body: <p>I was given an assignment to modify an 8 Queens program to use a 1D array and to use brute force (already did backtracking). I've come up with the following code:</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  bool ok(int board[8]){
  
  for(int j = 0; j &lt;= 7; j++){ //check for repeating digits
      cout &lt;&lt; "ok loop 1"&lt;&lt;endl;
      for (int k = 0; k &lt;= 7; k++)
      {
          cout &lt;&lt; "ok loop 2"&lt;&lt;endl;
          if (board[k] = board[j]){ return false; }
      }
  }
  
  for(int c = 7; c &gt;= 0; c--){ //check if position is safe
      cout &lt;&lt; "ok loop 3"&lt;&lt;endl;
      //int r = 0;
  
      for(int i = 1; i &lt;= c; i++){
      cout &lt;&lt; "ok loop 4"&lt;&lt;endl;
          if(board[c-i] == c)
              return false;
          else if ((board[c]-i)&gt;0 &amp;&amp; board[c-i]-i == 1)
  
              return false;
          else if ((board[c]+i)&lt;=7 &amp;&amp; board[c-i]+i == 1)
              return false;
      } // for loop
  
  } // for loop
      return true;
  } // ok
  
  
  
  
  void print(int board[8], int c){
  cout &lt;&lt; "Solution " &lt;&lt; c &lt;&lt; ": " &lt;&lt; endl;
  for(int i = 0; i &lt; 8; i++){
  {
      cout &lt;&lt; board[i] &lt;&lt;" ";
  } 
  }
  
  cout &lt;&lt; endl;
  } 
  
  
  
  
  int main ()
  {
  
  int b[8]={0}; //initialize the array
  int count = 0;
  
  for(b[0]=0; b[0]&lt;8; b[0]++)
  for(b[1]=0; b[1]&lt;8; b[1]++)
      for(b[2]=0; b[2]&lt;8; b[2]++)
          for(b[3]=0 ; b[3]&lt;8; b[3]++)
              for(b[4]=0; b[4]&lt;8; b[4]++)
                  for(b[5]=0; b[5]&lt;8; b[5]++)
                      for(b[6]=0; b[6]&lt;8; b[6]++)
                          for(b[7]=0; b[7]&lt;8; b[7]++)
                              if(ok(b)) 
                              {
                                  count++;
                                  print(b, count);
                              }
  system("PAUSE");
  return 0;
  }
  </code></pre>
  
  <p>It keeps looping forever and I am not sure why. Would anyone mind helping me?</p>