Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Re: Re: The N-queens problem using pure regexesby benizi (Hermit) |
on Oct 10, 2003 at 19:58 UTC ( [id://298393]=note: print w/replies, xml ) | Need Help?? |
For (e.g., for $N = 11: [ a1, b3, c5, d7, e9, f11, g2, h4, i6, j8, k10 ]) This is equivalent to starting in the bottom-left corner of the board and moving right one square and up two squares (wrapping when you hit the edge) N-1 times. If the regex picks the first space not-already-capturable in each column (From brief inspection, it appears to do so -- It finds an equivalent solution for odd-N), this is the first solution it will find. In the even-N case, this process will not leave any not-already-capturable squares in the last column on the first pass, so it must then backtrack. Update: Whoa there, Ben. I spoke way too soon. The above solution only applies when N is odd AND not divisible by 3. (So, for N = (1,5) mod 6) More update: I was wrong about most of the analysis, too. This won't be the first solution found.
In Section
Meditations
|
|