Largest palindrome product: Difference between revisions
→{{header|Raku}}: use external library for 25x speedup (still slow, but not dreadful)
(→{{header|Go}}: Updated as per Wren.) |
Thundergnat (talk | contribs) (→{{header|Raku}}: use external library for 25x speedup (still slow, but not dreadful)) |
||
Line 75:
=={{header|Raku}}==
<lang perl6>use Prime::Factor;▼
.say for (1..11).hyper(:1batch).map: {.&lpp};▼
my $p5 = Inline::Perl5.new();
$p5.use: 'ntheory';
my &divisors = $p5.run('sub { ntheory::divisors $_[0] }');
multi lpp ($oom where {$_ +& 1}) { # even number of multiplicand digits▼
my $f = +(9 x ($oom + 1));▼
▲multi lpp ($oom where {!($_ +& 1)}) { # even number of multiplicand digits
my $o = (1 + $oom) / 2;▼
my $
sprintf "Largest palindromic product of two %2d-digit integers: %d × %d = %d", $oom + 1, $pal div $f, $f, $pal▼
▲ sprintf "Largest palindromic product of two %2d-digit integers: %d × %d = %d", $oom
}
multi lpp ($oom where {$_ +
my $p;
(+(1 ~ (0 x ($oom - 1))) .. +(9 ~ (9 x ($oom - 1)))).reverse.map({ +($_ ~ .flip) }).map: -> $pal {
for my @factors = divisors("$pal")».
next unless $pal div $_ ∈ @factors;
$p = sprintf("Largest palindromic product of two %2d-digit integers: %d × %d = %d", $oom
last;
}
last if $p;
|