Ormiston triples: Difference between revisions

Content added Content deleted
(→‎{{header|J}}: append Pascal version)
m (→‎{{header|Free Pascal}}: minimal enhancement)
Line 211: Line 211:
checking for used digits like [[Ormiston_triples#Go]] and removed mod 18 calculation by using an array of boolean [0..990] with every 18 marked as true.Not as effective as I expected .
checking for used digits like [[Ormiston_triples#Go]] and removed mod 18 calculation by using an array of boolean [0..990] with every 18 marked as true.Not as effective as I expected .
<syntaxhighlight lang=pascal>
<syntaxhighlight lang=pascal>
program Ormiston3;
program Ormiston;
{$IFDEF FPC}{$MODE DELPHI} {$OPTIMIZATION ON,ALL}{$ENDIF}
{$IFDEF FPC}{$MODE DELPHI} {$OPTIMIZATION ON,ALL}{$ENDIF}
{$IFDEF WINDOWS}{$APPLICATION CONSOLE}{$ENDIF}
{$IFDEF WINDOWS}{$APPLICATION CONSOLE}{$ENDIF}
Line 582: Line 582:
end;
end;


function Convert2Digits10(p:NativeUint):Uint64;
function Convert2Digits10(p:NativeUint):Uint64;inline;
const
const
smlPrimes : array[0..9] of integer = (2,3,5,7,11,13,17,19,23,29);
smlPrimes : array[0..9] of integer = (2,3,5,7,11,13,17,19,23,29);
Line 595: Line 595:
until r = 0;
until r = 0;
end;
end;

function CheckOrmiston(const d1,d2:tpd10_UsedDgts3):boolean;inline;
begin
result := (d1^[0]=d2^[0]) AND (d1^[1]=d2^[1]);
end;

var
{$align 32}
{$align 32}
var
IsMod18 : array[0..(1000 DIV 18)*18] of boolean;
IsMod18 : array[0..(1000 DIV 18)*18] of boolean;
procedure OneRun;
{$align 32}
var
p1,p2 : Uint64;
{$align 32}
pr1,pr2,pr3,prLimit :nativeInt;
p1 : Uint64;
pr1,pr2,pr3,prLimit :nativeUInt;
cnt,prCnt : NativeUint;
cnt,prCnt : NativeUint;
begin
Begin
pr1 := 0;
preSieveInit;
pr2 := 0;
sievePrimesInit;
InitPrime;
For pr1 := 1 to 1000 DIV 18 do
IsMod18[18*pr1] := true;
pr1 := 0;
pr2 := 0;
prCnt := 0;
prCnt := 0;
prLimit := 10*1000*1000;
prLimit := 10*1000*1000;
repeat
repeat
inc(prCnt);
inc(prCnt);
pr3 := pr2;
pr3 := pr2;
pr2 := pr1;
pr2 := pr1;
pr1 := nextprime;
pr1 := nextprime;
until pr1 > prLimit;
until pr1 > prLimit;
prLimit *= 10;
prLimit *= 10;

cnt := 0;
cnt := 0;
repeat
repeat
Line 633: Line 623:
begin
begin
p1 := Convert2Digits10(pr3);
p1 := Convert2Digits10(pr3);
p2 := Convert2Digits10(pr2);
if Convert2Digits10(pr2) = p1 then
if p1= p2 then
if IsMod18[pr1-pr2] then
if IsMod18[pr1-pr2] then
begin
begin
p1 := Convert2Digits10(pr1);
if Convert2Digits10(pr1) =p1 then
if p1=p2 then
begin
begin
inc(cnt);
inc(cnt);
Line 644: Line 632:
OutIn(cnt,pr1);
OutIn(cnt,pr1);
end
end
end
end
end;
end;
if pr1 >=prLimit then prlimit:= OutByPot10(cnt,prlimit);
if pr1 >=prLimit then
prlimit:= OutByPot10(cnt,prlimit);
pr3 := pr2;
pr2 := pr1;
pr3 := pr2;
pr2 := pr1;
pr1 := nextprime;
pr1 := nextprime;
until pr2 > limit;
until pr2 > limit;
writeln(' prime count ',prCnt);
writeln(' prime count ',prCnt);
writeln(' last primes ',pr3:12,pr2:12,pr1:12);
writeln(' last primes ',pr3:12,pr2:12,pr1:12);
end;
end.</syntaxhighlight>

var
j :Int32;
Begin
preSieveInit;
sievePrimesInit;
InitPrime;

j := 0;
while j < High(IsMod18)do
Begin
IsMod18[j] := true;
j += 18;
end;

OneRun;
end.
</syntaxhighlight>
{{out|@TIO.RUN}}
{{out|@TIO.RUN}}
<pre>
<pre>
11,117,321 12,980,873 14,964,107 32,638,321 32,964,431
11,117,321 12,980,873 14,964,107 32,638,321 32,964,431
33,539,873 35,868,103 44,058,103 46,103,327 48,015,103
33,539,873 35,868,103 44,058,103 46,103,327 48,015,103
50,324,327 52,402,873 58,005,329 60,601,327 61,395,329
50,324,327 52,402,873 58,005,329 60,601,327 61,395,329
74,699,897 76,012,987 78,163,231 80,905,987 81,966,431
74,699,897 76,012,987 78,163,231 80,905,987 81,966,431
82,324,327 82,523,107 83,279,873 86,050,871 92,514,431
82,324,327 82,523,107 83,279,873 86,050,871 92,514,431
25 Ormiston triples before 100,000,000
25 Ormiston triples before 100,000,000
368 Ormiston triples before 1,000,000,000
368 Ormiston triples before 1,000,000,000
Line 666: Line 673:
prime count 455052513
prime count 455052513
last primes 9999999967 10000000019 10000000033
last primes 9999999967 10000000019 10000000033
Real time: 16.905 s CPU share: 99.00 %
Real time: 15.780 s CPU share: 99.20 %
</pre>
</pre>