Penholodigital squares: Difference between revisions

Added Perl
m (→‎slightly faster: i meant +400)
(Added Perl)
Line 923:
sys 0m0.042s
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>use v5.36;
use List::Util 'max';
use ntheory <fromdigits todigitstring>;
 
sub table ($c, @V) { my $t = $c * (my $w = 2 + max map { length } @V); ( sprintf( ('%'.$w.'s')x@V, @V) ) =~ s/.{1,$t}\K/\n/gr }
 
for my $base (9 .. 12) {
my $testr = reverse my $test = substr('123456789abcdef',0,$base-1);
my $start = int sqrt fromdigits($test, $base);
my $end = int sqrt fromdigits($testr, $base);
my @nums = grep { $test eq join '', sort split '', todigitstring($_**2, $base) } $start .. $end;
printf "There are a total of %d penholodigital squares in base $base:\n", scalar @nums;
say table 4, map { todigitstring($_,$base) . '² = ' . todigitstring($_**2,$base) } @nums;
}
</syntaxhighlight>
{{out}}
<pre>There are a total of 10 penholodigital squares in base 9:
3825² = 16328547 3847² = 16523874 4617² = 23875614 4761² = 25487631
6561² = 47865231 6574² = 48162537 6844² = 53184267 7285² = 58624317
7821² = 68573241 8554² = 82314657
 
There are a total of 30 penholodigital squares in base 10:
11826² = 139854276 12363² = 152843769 12543² = 157326849 14676² = 215384976
15681² = 245893761 15963² = 254817369 18072² = 326597184 19023² = 361874529
19377² = 375468129 19569² = 382945761 19629² = 385297641 20316² = 412739856
22887² = 523814769 23019² = 529874361 23178² = 537219684 23439² = 549386721
24237² = 587432169 24276² = 589324176 24441² = 597362481 24807² = 615387249
25059² = 627953481 25572² = 653927184 25941² = 672935481 26409² = 697435281
26733² = 714653289 27129² = 735982641 27273² = 743816529 29034² = 842973156
29106² = 847159236 30384² = 923187456
 
There are a total of 20 penholodigital squares in base 11:
42045² = 165742a893 43152² = 173a652894 44926² = 18792a6453 47149² = 1a67395824
47257² = 1a76392485 52071² = 249a758631 54457² = 2719634a85 55979² = 286a795314
59597² = 314672a895 632a4² = 3671a89245 64069² = 376198a254 68335² = 41697528a3
71485² = 46928a7153 81196² = 5a79286413 83608² = 632a741859 86074² = 6713498a25
89468² = 7148563a29 91429² = 76315982a4 93319² = 795186a234 a3a39² = 983251a764
 
There are a total of 23 penholodigital squares in base 12:
117789² = 135b7482a69 16357b² = 23a5b976481 16762b² = 24ab5379861 16906b² = 25386749ba1
173434² = 26b859a3714 178278² = 2835ba17694 1a1993² = 34a8125b769 1a3595² = 354a279b681
1b0451² = 3824b7569a1 1b7545² = 3a5b2487961 2084a9² = 42a1583b769 235273² = 5287ba13469
2528b5² = 5b23a879641 25b564² = 62937b5a814 262174² = 63a8527b194 285a44² = 73b615a8294
29a977² = 7b9284a5361 2a7617² = 83ab5479261 2b0144² = 8617b35a294 307381² = 93825a67b41
310828² = 96528ab7314 319488² = 9ab65823714 319a37² = 9b2573468a1</pre>
 
=={{header|Phix}}==
2,392

edits