N-Queens Problem. Brute force solution. Debugging help needed

• 03-20-2004
Tethys
N-Queens Problem. Brute force solution. Debugging help needed
As you probably know, the N-Queens problem involves placing N- queens on an NxN chess board such that no two queens are attacking each other. I'm trying out a brute force method to get this working.

Strangely enough, it works for N values Less than 9. But for N=9,10,11,... etc., the code fails. I am unable to ascertain why this is happening.

I've attached the entire code for the problem. I'd appreciate if someone told me where it is failing.

The value N is implemented as a macro BS in the code, almost on top. The output is a matrix of 0's and 1's. A 1 represents a queen, a 0 is a blank square.

• 03-21-2004
Codeplug
>> I'm trying out a brute force method to get this working.

That's not a brute force method for solving that problem.
A "brute force" method implies that every combination of an N-queen layout is attempted on an NxN board.

At each attempt, your algorithm is placing the first queen at every position on the board, then tries to place the remaining N-1 queens by the scanning the entire board for a safe position. This does not try every combination of an N-queen layout.

A simplified brute force algorithm is discussed here (the second hit returned by google).

gg
• 03-21-2004
Tethys
Hmm, I suppose you're right.

Still no solution...