
« #4 : January 22, 2008, 05:17:47 PM From thequark» 

Actually it is a classical N queens problem often discussed when discussing constraint satisfaction problems (CSP) or backtracking algorithmic approach.
The most brute force approach would be to take a vector of 8 integers. (0,0,0,0,0,0,0,0) where each element can vary from 0 to 8. ith number in the vector gives row number of queen in ith column. Now starting incrementing them to cover all the possible combinations (0,0,0,0,0,0,0,0) > ... > (7,7,7,7,7,7,7,7) which would be 8^8 and in general n^n. In each of the vector check whether a queen is capturing another one or not.
Now there can be various ways to enhance this algorithm e.g. assign row values from left to right and each time you try to assign a particular value check whether it conflicts with the existing values in left. The same value can't be present right as no two queens can be present at the same row and check for diagonal also.
There can be other strategies to solve the problem also
