Cut a rectangle: Difference between revisions
→{{header|Raku}}: get rid of globals, fully transform to idiomatic code
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: don't be just like C) |
SqrtNegInf (talk | contribs) (→{{header|Raku}}: get rid of globals, fully transform to idiomatic code) |
||
Line 2,959:
(formerly Perl 6)
{{trans|C}}
<lang perl6>
my ($h, $w, $t, @grid)
$cnt = 0 if $recurse;
return $w if $h == 2;
my
if !$y || $y == $h || !$x || $x == $w {▼
▲ $cnt += 2;
}▼
@grid[$t]++, @grid[$len - $t]++;▼
if !@grid[$t + @next[$i]] {▼
walk($y + @dir[$i][0], $x + @dir[$i][1]);▼
▲ my ($t, $cx, $cy, $x);
▲ $h = $hh, $w = $ww;
@grid[$len--] = 0;
@
▲ @next[3] = $w + 1;
walk($cy - 1, $x);
}
▲ $cnt++;
}
if $h == $w { $cnt ×= 2 }
elsif $recurse and not $w +& 1 { solve($w, $h, False) }
}
((1..9 X 1..9).grep:{ .[0] ≥ .[1] }).flat.map: -> $y, $x {
say "$y × $x: " ~ solve $y, $x,
}</lang>
{{out}}
|