Penholodigital squares

Revision as of 22:59, 3 February 2023 by Rdm (talk | contribs) (J)

Penholodigital squares are perfect square numbers that contain all of the digits from the base in which the number is represented, except for zero, exactly once.

Penholodigital squares is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
From the Latin prefix pene- (before, or next to, nearly)

and holo- (whole, or all)

penholodigital: Nearly-all-digits.

So, in a particular base, a penholodigital square number will contain all of the digits used in that base (except zero) once, and only once. Base eight penholodigitals contain the digits 1 through 7, base 10, 1 through 9, etc.


For example

In base 10, 139854276 is a penholodigital square. It is the square of the integer 11826, and contains every digit from 1 through 9 exactly once.


Penholodigital squares can occur in many, though not every, base. They tend to be pretty rare in lower bases.

There is a total of 1 penholodigital squares in base 2:
1² = 1

There is a total of 0 penholodigital squares in base 3:

There is a total of 0 penholodigital squares in base 4:

There is a total of 0 penholodigital squares in base 5:

There is a total of 2 penholodigital squares in base 6:
122² = 15324, 221² = 53241

There is a total of 1 penholodigital squares in base 7:
645² = 623514

There is a total of 1 penholodigital squares in base 8:
2453² = 6532471


Task

Find and display the total count, and the penholodigital squares and the integers that are squared to produce them, represented in the base in which they are calculated, for bases 9, 10, 11 and 12.


Stretch

Find and display the total count, and the first and last penholodigital squares and the integers that are squared to produce them, represented in the base in which they are calculated, for bases 13, 14, 15, ... ?


See also


J

Implementation:

digch=: a.{~;48 97(+i.)&.>10 26
brep=: (digch {~ #.inv)&.>

penholod=: {{
  F=: >.%:y#.D=:}.i.y
  C=: <.%:y#.}:i.-y
  ok=: (D */@e. y #.inv ])"0
  (#~ok) *:F+i.1+C-F
}}

task=: {{
  sq=. penholod y
  hd=. ,:(#sq),&":' penholodigital squares in base ',":y
  hd,(*#sq)#names (y brep sq),each '=',each(y brep %:sq),each<'²'
}}

Task examples:

   task 9
10 penholodigital squares in base 9                                                             
16328547=3825² 16523874=3847² 23875614=4617² 25487631=4761² 47865231=6561² 48162537=6574² 
53184267=6844² 58624317=7285² 68573241=7821² 82314657=8554²                                 
   task 10
30 penholodigital squares in base 10                                                                        
139854276=11826² 152843769=12363² 157326849=12543² 215384976=14676² 245893761=15681² 254817369=15963² 
326597184=18072² 361874529=19023² 375468129=19377² 382945761=19569² 385297641=19629² 412739856=20316² 
523814769=22887² 529874361=23019² 537219684=23178² 549386721=23439² 587432169=24237² 589324176=24276² 
597362481=24441² 615387249=24807² 627953481=25059² 653927184=25572² 672935481=25941² 697435281=26409² 
714653289=26733² 735982641=27129² 743816529=27273² 842973156=29034² 847159236=29106² 923187456=30384² 
   task 11
20 penholodigital squares in base 11                                                           
165742a893=42045² 173a652894=43152² 18792a6453=44926² 1a67395824=47149² 1a76392485=47257² 
249a758631=52071² 2719634a85=54457² 286a795314=55979² 314672a895=59597² 3671a89245=632a4² 
376198a254=64069² 41697528a3=68335² 46928a7153=71485² 5a79286413=81196² 632a741859=83608² 
6713498a25=86074² 7148563a29=89468² 76315982a4=91429² 795186a234=93319² 983251a764=a3a39² 
   task 12
23 penholodigital squares in base 12                                                                     
135b7482a69=117789² 23a5b976481=16357 24ab5379861=16762 25386749ba1=16906 26b859a3714=173434² 
2835ba17694=178278² 34a8125b769=1a1993² 354a279b681=1a3595² 3824b7569a1=1b0451² 3a5b2487961=1b7545² 
42a1583b769=2084a9² 5287ba13469=235273² 5b23a879641=2528b5² 62937b5a814=25b564² 63a8527b194=262174² 
73b615a8294=285a44² 7b9284a5361=29a977² 83ab5479261=2a7617² 8617b35a294=2b0144² 93825a67b41=307381² 
96528ab7314=310828² 9ab65823714=319488² 9b2573468a1=319a37²                                           
   task 13
0 penholodigital squares in base 13                                                            
   task 14
160 penholodigital squares in base 14                                                           
126a84d79c53b=1129535² 12a68db5374c9=1145393² 134596cab87d2=117d854² 1356bc247d9a8=11865a8² 
135bad2678c49=11888a3² 146ca78d53b92=1213aca² 149785ac62d3b=1225aa9² 14bc765da8329=1235dc3² 
157ab3d289c64=1279052² 15a29d468c73b=12894a5² 15a8364dc7b29=128b953² 1623d89b7a5c4=12b30ac² 
167b48acd3952=12d71b4² 1763d8ca9245b=13485d5² 17bd495ac8632=136c494² 182c6d7534a9b=138bc89² 
183d645b72ac9=1393b93² 185b36d7a4c92=13a0084² 1a3d7c6925b48=1461c78² 1a6548739c2db=1470999² 
1ad8546c37b92=149aa14² 1bca2d5736849=1508ca3² 1c25a647d893b=151db35² 1c398ad765b24=152649 
1d38ab65c7249=1576cab² 1d4965c8ba237=157c257² 1d527b3a6c489=15809d3² 1d64ba5c89237=1586757² 
23457bcd861a9=16d1b9 26adb397548c1=180d3d1² 2761354d9cba8=183b736² 283cad946157b=1877349² 
29d738461ac5b=190aa09² 2a9657c148d3b=193aaa9² 2bd357619ac48=19910d6² 2c35164a98d7b=19a4195² 
2d56b71c34a89=1a1030 2d785c3691ba4=1a18b62² 32cda84759b61=1b11831² 34b17956cda28=1b84906² 
34da578296c1b=1b909d9² 359c84ad761b2=1bbb53 3674bc2598da1=1c0c851² 36ba29d587c41=1c21091² 
36cd78a95b241=1c25991² 38c2a5db71964=1c9891 391b6c2475da8=1ca7d36² 3978b56a4cd12=1cc1274² 
3a1cd2476985b=1d034d5² 3a716d45b92c8=1d18196² 3b74ac96d1528=1d53476² 3c4da1285769b=1d82b89² 
3c6a79415d8b2=1d891aa² 3cb8216d57a49=1d9c33 3dc529a78b164=1dd841 41952d3a67bc8=205b2b8² 
41d5ba69c8237=206b1c7² 427589d63ac1b=208a775² 43ac6db981572=20d0164² 46185c9adb732=216bbba² 
46518b2c3d7a9=217972 467a53289dc1b=21842d9² 4756d93b12ca8=21b1038² 47921586cad3b=21bd039² 
48ad25c19b637=22188b7² 48cb93d567a12=2220ada² 48d593ba76c12=22228da² 49db5a71c3628=2257406² 
4a619c8d5273b=226d835² 4a6c7d1385b29=227211 4ab96d12753c8=22835b8² 4c3b528da1769=22cb813² 
4ca59718362db=2304629² 5329784cdab61=2402131² 5348c7a6b9d21=24080cd² 537cd86a941b2=24141a4² 
54a7b93cd1628=244c9d8² 564cbd78321a9=249a12 57ab12834d6c9=24dd54 59a6148d3cb72=255ad7 
59ab746d1c328=255c168² 5a12d34c78b69=256ad5 5a48c673b1d29=2576d8 5a9328c641d7b=2586549² 
5a9b6c21d7348=2588178² 5b23ca79d4681=259ccb1² 5c1438adb2769=25c895 5c24a986d317b=25cb949² 
5c3d784ab6129=25d251 5d36c7418a9b2=261d43 5d6789ac41b32=26280ba² 5d7b861ca4329=262ba53² 
5da41c73689b2=2634b3 61374a895bcd2=267941 63ab275d49c81=270a8b1² 65dbc7a914328=276cc76² 
67458db39a2c1=27a7d0 683db5a9742c1=27d30d1² 68d5a943c721b=2810a05² 68da3c95b1724=2811842² 
69c5b1738ad24=2837d42² 6a975bc843d21=2859d11² 7254638a1dc9b=296b7c5² 74d6ca935b128=29d7768² 
793185c2dab64=2aa5c1 7a3d28b14c569=2ad13cb² 7b63459ca8d21=2b20281² 7b6ca139854d2=2b21c1 
7cd13ab529648=2b5a308² 83cd916a574b2=2c40134² 86da721493c5b=2cb5679² 8915b2adc4637=2d26547² 
8b1d75a2c3649=2d740a3² 8c415da92637b=2da0095² 95162dca8437b=30bb095² 95317bc2d68a4=30c0c0 
95b83dc167a24=30d632 95bc8347ad612=30d6d04² 9841b5a6cd237=3150917² 9a175d382cb64=3191c1 
9a261b73cd584=3193c92² 9b5a1726cd348=31c0878² 9c6b3d2a51748=3206366² a195234db7c68=3276c18² 
a19d2cb854637=32781b7² a4c918563d7b2=3307d3 a87b49365cd21=33867cd² a93b857c4d612=33a00da² 
a95847c2d361b=33a3bd9² ab6c8d5793241=340a621² ad139726c5b48=3441c78² b27146dc359a8=34b4836² 
b8a5d174c2369=35a38cb² b917a2856d3c4=35b0232² ba3c52d796481=35d5841² ba7d48361c529=35ddc8 
bc5a68d479321=363a5cd² c152b73da9648=369a308² c2b9a43d87561=36c9531² c349b5721ad68=36d9588² 
c5321a47bd689=373627 c53729468bda1=3736c8 c63b78a1d5249=37574a3² c64981abd5237=3759087² 
c7a5d493861b2=37861a4² c9d84ab316752=37cb72 cb548a369d172=381827 cd37b496512a8=38534a6² 
cd6ab81395724=3859842² d21396874ac5b=38aa3d5² d28a3b549c761=38ba9a1² d3b5c9612a784=3900b4 
d42795b36a1c8=390a926² d5c742ba31689=39407d3² d64895a723c1b=394c2d9² d764ab895c321=397025 
d912c45a6873b=39a1835² d981746a53cb2=39b0934² da135b28c7964=39c021 db3962a7541c8=3a03226² 
   NB. this is getting to be obnoxiously long...

Raku

(9 .. 12).map: -> $base {
    my $test = (1 ..^ $base)».base($base).join;
    my $start = $test     .parse-base($base).sqrt.Int;
    my $end   = $test.flip.parse-base($base).sqrt.Int;
    say "\nThere is a total of {+$_} penholodigital squares in base $base:\n" ~
        .map({"{.base($base)}² = {.².base($base)}"}).batch(3)».join(", ").join: "\n" given
        ($start .. $end).grep: *².base($base).comb.sort.join eq $test
}

(13 .. 16).hyper(:1batch).map: -> $base {
    my $test = (1 ..^ $base)».base($base).join;
    my $start = $test     .parse-base($base).sqrt.Int;
    my $end   = $test.flip.parse-base($base).sqrt.Int;
    my @penholo = ($start .. $end).grep: *².base($base).comb.sort.join eq $test;
    say "\nThere is a total of {+@penholo} penholodigital squares in base $base:";
    say @penholo[0,*-1].map({"{.base($base)}² = {.².base($base)}"}).batch(3)».join(", ").join: "\n" if +@penholo;
}
Output:
There is 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 is 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 is 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 is 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

There is a total of 0 penholodigital squares in base 13:

There is a total of 160 penholodigital squares in base 14:
1129535² = 126A84D79C53B, 3A03226² = DB3962A7541C8

There is a total of 419 penholodigital squares in base 15:
4240C58² = 12378DA5B6EC94, EE25E4A² = ED4C93285671BA

There is a total of 740 penholodigital squares in base 16:
11156EB6² = 123DA7F85BCE964, 3FD8F786² = FEC81B69573DA24