Zhang-Suen thinning algorithm: Difference between revisions

m
→‎{{header|Perl}}: quiet the warnings about 'uninitialized' variables
m (syntax highlighting fixup automation)
m (→‎{{header|Perl}}: quiet the warnings about 'uninitialized' variables)
Line 3,574:
=={{header|Perl}}==
{{trans|Raku}}
<syntaxhighlight lang="perl">use List::Util qw(sum min)v5.36.0;
no warnings 'uninitialized';
use List::Util qw(sum min);
 
$source = <<'END';
Line 3,612 ⟶ 3,614:
 
do {
sub seewhite ($w1,$w2) {
my($w1,$w2) = @_results;
sub cycles (@neighbors) { my $c; $c += $neighbors[$_] < $neighbors[($_+1)%8] for 0..$#neighbors; $c }
my(@results);
sub cyclesblacks { my(@neighbors)=@_; my{ $c;sum $c += $@neighbors[$_] < $neighbors[($_+1)%8] for 0..$#neighbors; return $c }
sub blacks { my(@neighbors)=@_; sum @neighbors }
 
@prior = @cand; @cand = ();
for $p (@prior) {
Line 3,627:
}
}
return @results;
}
 
@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;
} untilwhile @goners1 == 0 andor @goners2 == 0;
 
while (@black) { push @thinned, join '', qw<. #>[splice(@black,0,$h)] }
 
printsay join "\n", @thinned;</syntaxhighlight>
{{out}}
<pre>............................................................
2,392

edits