Flipping bits game: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: future-proof for 5.36, use new bitwise string operators) |
||
Line 4,367: | Line 4,367: | ||
valid rows or columns, and disregards any irrelevant text in between. |
valid rows or columns, and disregards any irrelevant text in between. |
||
<syntaxhighlight lang="perl"> |
<syntaxhighlight lang="perl">use strict; |
||
use strict; |
|||
use warnings qw(FATAL all); |
use warnings qw(FATAL all); |
||
use feature 'bitwise'; |
|||
my $n = shift(@ARGV) || 4; |
my $n = shift(@ARGV) || 4; |
||
Line 4,392: | Line 4,392: | ||
{ |
{ |
||
for(@rows, @cols) { |
for(@rows, @cols) { |
||
$start ^= $_ if int rand 2; |
$start ^.= $_ if int rand 2; |
||
} |
} |
||
redo if $start eq $goal; |
redo if $start eq $goal; |
||
Line 4,432: | Line 4,432: | ||
$did_one = 1; |
$did_one = 1; |
||
if( /\d/ ) { |
if( /\d/ ) { |
||
$start ^= $rows[$_-1]; |
$start ^.= $rows[$_-1]; |
||
} else { |
} else { |
||
$_ = ord(lc) - ord('a'); |
$_ = ord(lc) - ord('a'); |
||
$start ^= $cols[$_]; |
$start ^.= $cols[$_]; |
||
} |
} |
||
++$moves_so_far; |
++$moves_so_far; |