Zhang-Suen thinning algorithm: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: quiet the warnings about 'uninitialized' variables) |
||
Line 3,574: | Line 3,574: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
<syntaxhighlight lang="perl">use |
<syntaxhighlight lang="perl">use v5.36.0; |
||
no warnings 'uninitialized'; |
|||
use List::Util qw(sum min); |
|||
$source = <<'END'; |
$source = <<'END'; |
||
Line 3,612: | Line 3,614: | ||
do { |
do { |
||
sub seewhite { |
sub seewhite ($w1,$w2) { |
||
my |
my @results; |
||
sub cycles (@neighbors) { my $c; $c += $neighbors[$_] < $neighbors[($_+1)%8] for 0..$#neighbors; $c } |
|||
my(@results); |
|||
sub |
sub blacks (@neighbors) { sum @neighbors } |
||
sub blacks { my(@neighbors)=@_; sum @neighbors } |
|||
@prior = @cand; @cand = (); |
@prior = @cand; @cand = (); |
||
for $p (@prior) { |
for $p (@prior) { |
||
Line 3,627: | Line 3,627: | ||
} |
} |
||
} |
} |
||
@results |
|||
} |
} |
||
@goners1 = seewhite [0,2,4], [2,4,6]; @black[@goners1] = 0 x @goners1; |
@goners1 = seewhite [0,2,4], [2,4,6]; @black[@goners1] = 0 x @goners1; |
||
@goners2 = seewhite [0,2,6], [0,4,6]; @black[@goners2] = 0 x @goners2; |
@goners2 = seewhite [0,2,6], [0,4,6]; @black[@goners2] = 0 x @goners2; |
||
} |
} while @goners1 or @goners2; |
||
while (@black) { push @thinned, join '', qw<. #>[splice(@black,0,$h)] } |
while (@black) { push @thinned, join '', qw<. #>[splice(@black,0,$h)] } |
||
say join "\n", @thinned;</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre>............................................................ |
<pre>............................................................ |