While reading Artificial Intelligence a Modern Approach I came across the following formulation for the 8-queen problem:
- Initial state: No queens on the board.
- States: Arrangements of n queens (0 <= n <= 8), one per column in the leftmost n columns, with no queen attacking another are states.
- Successor function: Add a queen to any square in the leftmost empty
colum such that it is not attacked by any other queen.
I have been trying to find some pattern that would allow me to sort out the number of states for each n given the constraints above but I have not been succeeded for n > 2.
So, for:
- n=1 => 8 states
- n=2 => 42 states
- …
Even though I could generate all the possible combinations for each n and then filter out all those that do not represent a valid state, I would rather not go that way because it would be really time and space consuming for n, say, greater or equal than 10.
To sum up, is there any sort of formula to find the number of states given n and at the same time taking into account the following constrains?
Best Answer
Here is a modest contribution while we wait for a professional answer to appear. You may be interested to know that even though the state space is easy to enumerate by backtracking, the numbers have not yet appeared in the OEIS!
The following Perl script implements the enumeration:
This yields the following data:
The OEIS has the number of solutions at OEIS A000170. I will try to see to it to enter the above triangular array into the OEIS giving the MSE post as one of the references.
Addendum. These data can now be found at OEIS A269133 where we hope additional useful references will appear (there are quite a number already which can be found in the linked to sequences).