[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

02/22/2005 at 05:57PM PST, ID: 21325259
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

N-Queens Problem: My Code Doesn't Work With n = 5, Sometimes Other n Too...

Asked by suprslackr in Java Programming Language

I have an n sized int array containing a permutation of 0...n. I use this to conceptualize an nXn chessboard, using the array index i for the rows of the board, and array[i] as the columns. So for a permutation of n = 4, I have, say, (2,1,0,3) , giving me a board with queens at (0,2),(1,1),(2,0),(3,3). This ensures that no two rows have a queen in the same column. I then call optimize() on this permutation, which checks whether there are attacks on the board (totalAttacks()). This total includes attack for queens a and b, for a to b and b to a, so a pair of attacking queens adds 2 to the count. numAttacks(int i) counts all attacks by the queen in the ith row, not including itself. swap(int i, int j) simply swaps the two elements at the given indices. so swap(0, 1) on the given permutation above gives me (1,2,0,3). fill() gives a new permutation if the current permutation cannot be optimized in this way. Below is the code for the optimize() method. It works pretty well for n < 15, but occasioinally hangs for n > 12, and always hangs for n = 5. Why does it hang for n = 5, why does it sometimes hang for other n, and what can I change to get this to work for n = 5 and larger (maybe up to n = 20)? Thanks in advance for your help -supr
        public void optimize() {
                int iathen, ianow, jathen, janow;
                while(totalAttacks() != 0) {
                        for(int i = 0; i < n; i++) {
                                for(int j = i + 1; j < n; j++) {
                                        iathen = numAttacks(i);
                                        jathen = numAttacks(j);
                                        if(iathen != 0 && jathen != 0) {
                                                swap(i, j);
                                                ianow = numAttacks(i);
                                                janow = numAttacks(j);
                                                if(iathen < ianow && jathen < janow)
                                                        swap(i, j);
                                                }

                                        }
                                if(i == n - 1)
                                        fill();
                                }
                        }
                }
[+][-]02/22/05 06:13 PM, ID: 13378209

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Sign Up Now!
Solution Provided By: objects
Participating Experts: 1
Solution Grade: B
 
 
[+][-]02/22/05 06:15 PM, ID: 13378214

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/22/05 06:26 PM, ID: 13378274

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02/22/05 06:29 PM, ID: 13378286

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02/22/05 06:32 PM, ID: 13378298

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/22/05 06:50 PM, ID: 13378384

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02/22/05 07:07 PM, ID: 13378451

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02/22/05 07:27 PM, ID: 13378543

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy