/*
* Buggy code, compile goog, running time error
*/
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define GRID_SIZE 8
bool checkValidity(int row, int* columns, int col){
for(int row1 = 0; row1 < row; row1++){
int column1 = columns[row1];
if(column1 == col)
return false;
int colDistance = abs(column1 - col);
int rowDistance = row - row1;
if(colDistance == rowDistance)
return false;
}
return true;
}
void placeQueen(int row, int* columns, vector<int *> results){
if(row == GRID_SIZE){
results.push_back(columns);
}else{
for(int col = 0; col < GRID_SIZE; col++){
if(checkValidity(row, columns, col)){
columns[row] = col;
placeQueen(row, columns, results);
}
}
}
}
int main() {
int columns[GRID_SIZE];
vector<int *> results;
placeQueen(0, columns, results);
return 0;
}