Penholodigital squares: Difference between revisions

m
→‎{{header|Free Pascal}}: added results for base 18,19 like Julia
m (→‎{{header|Free Pascal}}: added results for base 18,19 like Julia)
Line 570:
{$IFDEF FPC}{$MODE DELPHI}{$Optimization ON,All}{$ENDIF}
{$IFDEF Windows}{$APPTYPE CONSOLE}{$ENDIF}
{$DEFINE TIORUN}
uses
sysutils;
const
charSet : array[0..1636] of char ='0123456789ABCDEF0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
type
tNumtoBase = record
Line 622 ⟶ 623:
end;
end;
 
procedure InsertSolution(i,penHoloCnt : NativeInt);
begin
sl[penHoloCnt] := Format('%s^2 = %s',[OutNum(Num),OutNum(sqr2B)]);
s2delta[penHoloCnt] := i;
{$IFNDEF TIORUN}
//a little action in the terminal
write(penHoloCnt:8,i :10,' ',sl[penHoloCnt],#13);
IF penHoloCnt= 0 then
writeln;
{$ENDIF}
end;
 
procedure IncNumBig(var add1:tNumtoBase;n:NativeUInt);
Line 705 ⟶ 718:
end;
 
procedure Test(base:NativeIntNativeUInt);
var
n,penHoloCnt : Uint64;
Line 713 ⟶ 726:
b1 := Base-1;
dgtRoot := ((Base*b1) DIV 2) MOD b1;
//number containing 1,2..,base-1
n := 0;
For j := 1 to b1 do
Begin
n := n* base + j;
dgtSqrRoot[j] := (j*j) MOD b1;
end;
// square number containing 1,2..,base-1
n := trunc(sqrt(n));
// now estimate root for 1234..Base-1
 
// if base is even then root = 111...1 in Base
// if base is odd then root = sqrt(base)*(111...1) in Base
n := 0;
For j := Base DIV 2 downto 1 do
n := n* base + j1;
if ODD(BASE) then
n := trunc(sqrtn*Sqrt(nbase));
// increment n til it fits (n*n) MOD b1 = dgtroot
j := B1;
repeat
if sqr(n*n MOD b1) MOD b1 = dgtroot then
BREAK;
inc(n);
dec(j);
until j = 0;
//calc nxn
Conv2num(Num,n,base);
deltaSqrNum := Num;
Conv2num(sqr2B,n*n0,base);
j := 1;
repeat
if j AND n <> 0 then
AddNum(sqr2B,deltaSqrNum);
AddNum(deltaSqrNum,deltaSqrNum);
j +=j;
until j > n;
// calc step size i
Conv2num(sqr2B,n*n,base);
Conv2num(Num,n,base);
 
// calc step size. i = occurences of same dgtroot.
i := 0;
For j := 1 to Base-1 do
if dgtSqrRoot[j] = dgtRoot then
inc(i);
// if i =stays 0 thenthan onean moreextra digit iswill be needed -> so no penholodigital number
if i <> 0 then
Begin
step := b1 DIV i;
Writeln('Step size ',step,' decimal : ',n,' in base: ',OutNum(Num),' ',OutNum(sqr2B));
// calc delta of square numbers for incremnt n by step
Conv2num(deltaSqrNum,2*step*n,base);
Line 760 ⟶ 785:
IF CheckSet=TestSet then
Begin
// now correct number
IncNumBig(num,i*step);
s2delta[penHoloCnt] := InsertSolution(i*step,penHoloCnt);
sl[penHoloCnt] := Format('%s^2 = %s',[OutNum(Num),OutNum(sqr2B)]);
inc(penHoloCnt);
i := 0;
Line 769 ⟶ 793:
//next square number
AddNum(sqr2B,deltaSqrNum);
IncNumBig(deltaSqrNum,dNum);// dnum maybe >=mostly base
inc(i);
until sqr2B.ntb_cnt >= base;
Line 776 ⟶ 800:
Begin
Writeln('Penholodigital squares in base: ',base:2,' are not possible');
writeln;
EXIT;
end
Line 798 ⟶ 823:
writeln(sl[0],',',sl[penHoloCnt-1]);
end;
writeln;
end;
 
Line 805 ⟶ 831:
begin
T0 := now;
setlength(sl,74051160);
setlength(s2Delta,74051160);
For base := 219 to 1719 do
Test(base);
writeln('Total runtime in s ',(now-T0)*86400:10:3);
Line 815 ⟶ 841:
{{out|@TIO.RUN}}
<pre style="height:40ex;overflow:scroll;">
Step size 1 decimal : 1 in base: 1 1
There are a total of 1 penholodigital squares in base: 2
1^2 = 1
 
Step size 2 decimal : 1 in base: 1 1
There are a total of 0 penholodigital squares in base: 3
 
Step size 3 decimal : 6 in base: 12 210
There are a total of 0 penholodigital squares in base: 4
 
Penholodigital squares in base: 5 are not possible
 
Step size 5 decimal : 45 in base: 113 13213
There are a total of 2 penholodigital squares in base: 6
122^2 = 15324,221^2 = 53241
 
Step size 6 decimal : 153 in base: 306 125151
There are a total of 1 penholodigital squares in base: 7
645^2 = 623514
 
Step size 7 decimal : 588 in base: 1114 1243220
There are a total of 1 penholodigital squares in base: 8
2453^2 = 6532471
 
Step size 4 decimal : 2462 in base: 3335 12357657
There are a total of 10 penholodigital squares in base: 9
3825^2 = 16328547,3847^2 = 16523874,4617^2 = 23875614
Line 831 ⟶ 871:
6844^2 = 53184267,7285^2 = 58624317,7821^2 = 68573241
8554^2 = 82314657
 
Step size 3 decimal : 11112 in base: 11112 123476544
There are a total of 30 penholodigital squares in base: 10
11826^2 = 139854276,12363^2 = 152843769,12543^2 = 157326849
Line 842 ⟶ 884:
26733^2 = 714653289,27129^2 = 735982641,27273^2 = 743816529
29034^2 = 842973156,29106^2 = 847159236,30384^2 = 923187456
 
Step size 10 decimal : 53415 in base: 3714A 1234599011
There are a total of 20 penholodigital squares in base: 11
42045^2 = 165742A893,A3A39^2 = 983251A764
 
Step size 11 decimal : 271458 in base: 111116 12346543230
There are a total of 23 penholodigital squares in base: 12
117789^2 = 135B7482A69,319A37^2 = 9B2573468A1
 
Penholodigital squares in base: 13 are not possible
 
Step size 13 decimal : 8108737 in base: 1111117 1234576543237
There are a total of 160 penholodigital squares in base: 14
1129535^2 = 126A84D79C53B,3A03226^2 = DB3962A7541C8
 
Step size 14 decimal : 47266835 in base: 4239EC5 123456E806A71A
There are a total of 419 penholodigital squares in base: 15
4240C58^2 = 12378DA5B6EC94,EE25E4A^2 = ED4C93285671BA
 
Step size 15 decimal : 286331160 in base: 11111118 123456876543240
There are a total of 740 penholodigital squares in base: 16
11156EB6^2 = 123DA7F85BCE964,3FD8F786^2 = FEC81B69573DA24
 
Penholodigital squares in base: 17 are not possible
Total runtime in s 7.159 @home 1.573 s
</pre>
<pre>
// Running Base 18 and 19 @home
Step size 17 decimal : 11668193559 in base: 111111119 12345679876543249
There are a total of 5116 penholodigital squares in base: 18
11150FC0G^2 = 123CD8ABH5G79F6E4,44422DD18^2 = HGEF25738D496BC1A
 
Step size 6 decimal : 78142392501 in base: 4B7ICE111 12345678BB48EGB321
There are a total of 47677 penholodigital squares in base: 19
4B802235A^2 = 1234978CIBD6GFHEA5,II844BIA2^2 = IHG8F71C6DA59BE324
Total runtime in s 1151.714
 
real 19m11.715s
user 19m10.257s
sys 0m0.042s
</pre>
 
132

edits