Magnanimous numbers: Difference between revisions

→‎{{header|Raku}}: various style / efficiency tweaks
m (Swift - simplified code)
(→‎{{header|Raku}}: various style / efficiency tweaks)
Line 916:
{{works with|Rakudo|2020.02}}
 
<lang perl6>my @magnanimous = lazy flat ^10, (10 .. 1001).hyper.map( {
my int $last;
(1 ..^ .chars - 1).map: -> \c { ++$last = 1 and last unless (.substr(0,c) + .substr(c)).is-prime }
next if $last;
$_
} ),
 
(1002 .. ∞).hyper.map: {
# optimization for numbers > 1001; First and last digit can not both be even or both be odd
next if (.substr(0,1) % 2 + .substr(*-1) % 2) %% 2;
my int $last;
(1 ..^ .chars - 1).map: -> \c { ++$last = 1 and last unless (.substr(0,c) + .substr(c)).is-prime }
next if $last;
$_
10,339

edits