# Thread: Help!! Need eight queens solution in C++

1. ## Help!! Need eight queens solution in C++

does anyone have a good, simple code that solves all 92 solutions to the eight queens problem? any help is appreciated.

2. 92 solutions to 8 queens, hmmmmm, er, hmmmm.

The 8-queens problem is a well-known constraint satisfaction problem (CSP) of classical AI.
oops: http://rana.usc.edu:8376/~yuri/queens/

Show me 1 solution, the 91 others will easily follow...

3. A friend of mine was trying to do the same thing but I think he was using PROLOG! Let me see what I can find!

4. This would work for more than one solution... not sure if it will give all 92 answers, prob just 64.

If you have a c++ code sample that will run similar to the applet.

1.Pick one row of the eight.
2.Pick one square of the eight in that row.
3.Select this square as being one with a queen.
4.Randomize the other 7 rows.
5.Set the selected queen as immovable.
6.Solve.
7.Pick another square in the same row.
8. repeat until all squares have been selected.

Banti

5. Banti,

I think the real question is how does one accomplish "6.Solve.".

Check out the above link, the guy does it in a neat applet (Yuri, you go boy!).

Another issue, and I just don't know, may be the existence of 'unsolvable' squares. If you place the first queen in 1,1 (assume 8,8 array), you may not be able to solve the problem. Again, I just don't know if any squares like that exist, as i have a solution with a queen in a corner.

Also, to truly capture all 92 solutions (how do we really know there are 92?), one needs to address the possibility that if I place the first queen on certain squares that have multiple solutions. Again, if one places queen in 1,1, there may exists 4 solution with a queen in 1,1.

Interesting problem, not exactly sure how I would solve (who's kidding who, I'd email Yuri).

6. too late is always good, right?

nothing impressive:

http://www.geocities.com/qballemail/8queens/8queens.htm

Post back with any questions/problems/wise-*** repsonses.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts

New Security Features Planned for Firefox 4
Another Laptop Theft Exposes 21K Patients' Data
Oracle Hits to Road to Pitch Data Center Plans
Microsoft Preps Array of Windows Patches
Microsoft Nears IE9 Beta With Final Preview
Simplified Analytics Improve CRM, BI Tools
Android Passes RIM as Top Mobile OS in 2Q