Peaceful chess queen armies: Difference between revisions
m
→Verbose: more efficient, return 1st result found
SqrtNegInf (talk | contribs) (→{{header|Perl}}: Added refactored version of code) |
SqrtNegInf (talk | contribs) m (→Verbose: more efficient, return 1st result found) |
||
Line 1,759:
W---W</pre>
===Verbose===
A refactored version of the same code, with fancier output
<lang perl>use strict;
use warnings;
Line 1,772:
sub place {
my($board, $n, $m, $empty_square) = @_;
state
# logic of 'attack' regex: queen ( ... paths between queens containing only empty squares ... ) queen of other color
$attack =
'([WB])' . # 1st queen▼
'(
}
# bail out if seen this configuration previously, or attack detected
Line 1,791 ⟶ 1,793:
# success if queen count is m×2
$solution = $board and
# place the next queen (alternating colors each time)
Line 1,804 ⟶ 1,806:
place( $board, $n, $m, $empty_square );
DONE: say $solution
? sprintf "Solution to $m $n\n\n%s", map { s/(.)/$1 /gm; s/B /♛/gm; s/W /♕/gmr } $solution
: "No solution to $m $n";</lang>
Line 1,810 ⟶ 1,812:
<pre>Solution to 4 5
• ♛• ♛•
♕◦ • ◦
▲♛• ◦ • ◦
▲• ◦ ♕◦ ♕
=={{header|Phix}}==
|