how does the regex engine not choose a free square in d4 when looking
for free squares in d3?
I do not know what you mean by this. Do you mean "why doesn't the
regex engine never try to place a queen on both d4 and d3?" In that
case, the answer is simple - it will never even attempt to place two
queens on the same column. The first part of the string is:
is being matched against the first part of the regex:
The newlines in the string and regex are significant here (. won't match
a newline). This part will make \1 one of 'a1' .. 'a8', \2 one of 'b1' ..
'b8', \3 one of 'c1' .. 'c8', etc. So, it will never try to place two
queens on the 'd' column.
But you may ask, "why doesn't it put a queen on d3 and one on e4?". That's
where the second part of the string and regex come in. \4 contains the
position of the queen on the d column, so, in this case, \4 equals 'd3'.
Then there's this line in the second part of the regex:
We know that \4 equals 'd3', so part of this lines read '\nd3:'. Looking
back at the second part of the string, there is only one line that starts
If you look carefully, after the colon are all the fields that aren't
attacked by a queen on d3. Specifically, the field 'e4' is missing.
But the line
is saying "match a line that starts with 'd3', and has after the colon
a list of fields that include the positions of all other 7 queens".
just skips enough lines to get to the next
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] |