Jump to content

Penholodigital squares: Difference between revisions

Added XPL0 example.
m (tidied link)
(Added XPL0 example.)
Line 1,448:
There is a total of 160 penholodigital squares in base 14:
1129535² = 126A84D79C53B 3A03226² = DB3962A7541C8
</pre>
 
=={{header|XPL0}}==
Real, 64-bit numbers provide the precision needed beyond 32-bit integers
to reach base 14 (14^13 = 7.94e14, which is 49.5 bits). Runs in 37
seconds on Pi4.
<syntaxhighlight lang "XPL0">real Base; \Number Base being used [9..14]
 
proc NumOut(N); \Display N in the specified Base
real N;
int Remain;
[Remain:= fix(Mod(N, Base));
N:= Floor(N/Base);
if N # 0. then NumOut(N);
ChOut(0, Remain + (if Remain <= 9 then ^0 else ^A-10));
];
 
proc ShowPenSq(N); \Display N = N^2
real N;
[NumOut(N);
Text(0, "^^2 = ");
NumOut(N*N);
Text(0, " ");
];
 
func Penholodigital(N); \Return 'true' if N is penholodigital
real N;
int Used, Remain;
[Used:= 1; \can't contain 0
while N # 0. do
[Remain:= fix(Mod(N, Base));
N:= Floor(N/Base);
if Used & 1<<Remain then return false;
Used:= Used ! 1<<Remain;
];
return Used = 1<<fix(Base) - 1;
];
 
int Cnt;
real N, Limit, FirstN, LastN;
[Base:= 9.;
repeat Cnt:= 0; FirstN:= 0.;
N:= Floor(Sqrt(Pow(Base, Base-2.)));
Limit:= sqrt(Pow(Base, Base-1.));
repeat if Penholodigital(N*N) then
[Cnt:= Cnt+1;
if FirstN = 0. then FirstN:= N;
if Base <= 12. then
[ShowPenSq(N);
if rem(Cnt/3) = 0 then CrLf(0);
]
else LastN:= N;
];
N:= N + 1.;
until N >= Limit;
if rem(Cnt/3) # 0 then CrLf(0);
Text(0, "There are "); IntOut(0, Cnt);
Text(0, " penholodigital squares in base ");
IntOut(0, fix(Base)); CrLf(0);
if Base >= 13. and Cnt > 0 then
[ShowPenSq(FirstN);
ShowPenSq(LastN);
CrLf(0);
];
CrLf(0);
Base:= Base + 1.;
until Base >= 15.;
]</syntaxhighlight>
{{out}}
<pre>
3825^2 = 16328547 3847^2 = 16523874 4617^2 = 23875614
4761^2 = 25487631 6561^2 = 47865231 6574^2 = 48162537
6844^2 = 53184267 7285^2 = 58624317 7821^2 = 68573241
8554^2 = 82314657
There are 10 penholodigital squares in base 9
 
11826^2 = 139854276 12363^2 = 152843769 12543^2 = 157326849
14676^2 = 215384976 15681^2 = 245893761 15963^2 = 254817369
18072^2 = 326597184 19023^2 = 361874529 19377^2 = 375468129
19569^2 = 382945761 19629^2 = 385297641 20316^2 = 412739856
22887^2 = 523814769 23019^2 = 529874361 23178^2 = 537219684
23439^2 = 549386721 24237^2 = 587432169 24276^2 = 589324176
24441^2 = 597362481 24807^2 = 615387249 25059^2 = 627953481
25572^2 = 653927184 25941^2 = 672935481 26409^2 = 697435281
26733^2 = 714653289 27129^2 = 735982641 27273^2 = 743816529
29034^2 = 842973156 29106^2 = 847159236 30384^2 = 923187456
There are 30 penholodigital squares in base 10
 
42045^2 = 165742A893 43152^2 = 173A652894 44926^2 = 18792A6453
47149^2 = 1A67395824 47257^2 = 1A76392485 52071^2 = 249A758631
54457^2 = 2719634A85 55979^2 = 286A795314 59597^2 = 314672A895
632A4^2 = 3671A89245 64069^2 = 376198A254 68335^2 = 41697528A3
71485^2 = 46928A7153 81196^2 = 5A79286413 83608^2 = 632A741859
86074^2 = 6713498A25 89468^2 = 7148563A29 91429^2 = 76315982A4
93319^2 = 795186A234 A3A39^2 = 983251A764
There are 20 penholodigital squares in base 11
 
117789^2 = 135B7482A69 16357B^2 = 23A5B976481 16762B^2 = 24AB5379861
16906B^2 = 25386749BA1 173434^2 = 26B859A3714 178278^2 = 2835BA17694
1A1993^2 = 34A8125B769 1A3595^2 = 354A279B681 1B0451^2 = 3824B7569A1
1B7545^2 = 3A5B2487961 2084A9^2 = 42A1583B769 235273^2 = 5287BA13469
2528B5^2 = 5B23A879641 25B564^2 = 62937B5A814 262174^2 = 63A8527B194
285A44^2 = 73B615A8294 29A977^2 = 7B9284A5361 2A7617^2 = 83AB5479261
2B0144^2 = 8617B35A294 307381^2 = 93825A67B41 310828^2 = 96528AB7314
319488^2 = 9AB65823714 319A37^2 = 9B2573468A1
There are 23 penholodigital squares in base 12
 
There are 0 penholodigital squares in base 13
 
 
There are 160 penholodigital squares in base 14
1129535^2 = 126A84D79C53B 3A03226^2 = DB3962A7541C8
 
</pre>
295

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.