in reply to Re: Re: The N-queens problem using pure regexes

in thread The N-queens problem using pure regexes

For ~~any odd N~~ odd N not divisible by 3: `$a_solution = [ map { chr(ord('a') + $_ - 1).(((2 * $_) - 1) % $N); } (1..$N) ]`

(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

Comment onRe: Re: Re: The N-queens problem using pure regexesDownloadCode