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

This is a discussion on N-Queens Problem. Brute force solution. Debugging help needed within the C Programming forums, part of the General Programming Boards category; As you probably know, the N-Queens problem involves placing N- queens on an NxN chess board such that no two ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    8

    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.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    >> 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

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    8
    Hmm, I suppose you're right.

    Still no solution...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Big Solution For Small Problem
    By GrNxxDaY in forum C++ Programming
    Replies: 8
    Last Post: 08-01-2002, 03:23 AM
  2. Odd solution to an odd problem
    By Zeeshan in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 07-20-2002, 05:44 PM
  3. debugging problem
    By _ag0nizer in forum C++ Programming
    Replies: 3
    Last Post: 06-10-2002, 05:26 PM
  4. debugging problem
    By _ag0nizer in forum C++ Programming
    Replies: 3
    Last Post: 06-03-2002, 09:47 AM
  5. Brute Force
    By Wiz_Nil in forum C++ Programming
    Replies: 13
    Last Post: 02-15-2002, 12:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21