Largest palindrome product: Difference between revisions
Content added Content deleted
(→{{header|Go}}: Updated as per Wren.) |
Thundergnat (talk | contribs) (→{{header|Raku}}: use external library for 25x speedup (still slow, but not dreadful)) |
||
Line 75: | Line 75: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
⚫ | |||
⚫ | |||
⚫ | |||
my $p5 = Inline::Perl5.new(); |
|||
$p5.use: 'ntheory'; |
|||
my &divisors = $p5.run('sub { ntheory::divisors $_[0] }'); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
my $ |
my $f = +(9 x $oom); |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
multi lpp ($oom where {$_ + |
multi lpp ($oom where {$_ +& 1}) { # odd number of multiplicand digits |
||
my $p; |
my $p; |
||
(+(1 ~ (0 x $oom)) .. +(9 ~ (9 x $oom))).reverse.map({ +($_ ~ .flip) }).map: -> $pal { |
(+(1 ~ (0 x ($oom - 1))) .. +(9 ~ (9 x ($oom - 1)))).reverse.map({ +($_ ~ .flip) }).map: -> $pal { |
||
for my @factors = $pal. |
for my @factors = divisors("$pal")».Int.grep({ .chars == $oom }).sort( -* ) { |
||
next unless $pal div $_ ∈ @factors; |
next unless $pal div $_ ∈ @factors; |
||
$p = sprintf("Largest palindromic product of two %2d-digit integers: %d × %d = %d", $oom |
$p = sprintf("Largest palindromic product of two %2d-digit integers: %d × %d = %d", $oom, $pal div $_, $_, $pal); |
||
last; |
|||
} |
} |
||
last if $p; |
last if $p; |