Do you know where your variables are? | |
PerlMonks |
Re: Trying to solve N-Queensby Solo (Deacon) |
on Sep 09, 2002 at 03:44 UTC ( [id://196146]=note: print w/replies, xml ) | Need Help?? |
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?
In Section
Seekers of Perl Wisdom
|
|