Largest palindrome product: Difference between revisions

Added Perl
(→‎{{header|Raku}}: use external library for 25x speedup (still slow, but not dreadful))
(Added Perl)
Line 73:
Largest palindromic product of two 9-digit integers: 999980347 x 999920317 = 999900665566009999
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<lang perl>use strict;
use warnings;
use feature 'say';
use ntheory 'divisors';
 
for my $l (2..7) {
LOOP:
for my $p (sort { $b <=> $a } map { $_ . reverse $_ } 10**($l-1) .. 10**$l - 1) {
my @f = sort { $b <=> $a } grep { length == $l } divisors $p;
next unless @f >= 2 and $p == $f[0] * $f[1];
say "Largest palindromic product of two @{[$l]}-digit integers: $f[1] × $f[0] = $p" and last LOOP;
}
}</lang>
{{out}}
<pre>Largest palindromic product of two 2-digit integers: 91 × 99 = 9009
Largest palindromic product of two 3-digit integers: 913 × 993 = 906609
Largest palindromic product of two 4-digit integers: 9901 × 9999 = 99000099
Largest palindromic product of two 5-digit integers: 99681 × 99979 = 9966006699
Largest palindromic product of two 6-digit integers: 999001 × 999999 = 999000000999
Largest palindromic product of two 7-digit integers: 9997647 × 9998017 = 99956644665999</pre>
 
=={{header|Raku}}==
2,392

edits