Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Trying to solve N-Queens

by Solo (Deacon)
on Sep 09, 2002 at 03:44 UTC ( [id://196146]=note: print w/replies, xml ) Need Help??


in reply to Trying to solve N-Queens

It appears to me, one problem arises (the one where the solutions sometimes are too short) when @TEMP is reset each time a solution is found, because we don't always start at the first column to find the next solution. We are only getting the part of the solution that is different from the previous one, since we didn't backtrack all the way to column 1 to rebuild @TEMP.

There has to be a pop @TEMP when we backtrack to the previous column, whether a solution is found or not. This should automatically clear @TEMP when we backtrack to the 1st column, making the @TEMP = (); line unecessary.

I0 has posted code above that corrects this problem, I believe.

On a side note, it appears you would be including non-distinct (AKA congruent) solutions in your results. Is this a concern?

Replies are listed 'Best First'.
Re: Re: Trying to solve N-Queens
by Solo (Deacon) on Sep 09, 2002 at 04:00 UTC
    Uh-oh... I missed that I0 already fixed the problem I pointed out... <ahem> Umm, nice job!

    Perhaps my post will clarify jeffa's coding problem and I0's solution for posterity.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://196146]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-18 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found