Anonymous user
Ludic numbers: Difference between revisions
m
→{{header|Pascal}}: speedup 4.4s -> 3 s. C-version is still at 1.25s for n= 100'000
({{header|Pascal}}) |
m (→{{header|Pascal}}: speedup 4.4s -> 3 s. C-version is still at 1.25s for n= 100'000) |
||
Line 1,328:
=={{header|Pascal}}==
Inspired by "rotors" of perl 6 .
Runtime nearly quadratic: maxLudicCnt = 10000 -> 0.
<lang pascal>program lucid;
{$IFDEF FPC}
{$MODE objFPC} // useful for x64
{$ENDIF}
const
//66164 -> last < 1000*1000;
maxLudicCnt = 2005;
type
tDelta = record
dNum
dCnt : LongInt;
end;
tpDelta = ^tDelta;
tLudicList = array of tDelta;
tArrdelta =array[0..0] of tDelta;
procedure getLudic(var Ll:tLudicList);▼
tpLl = ^tArrdelta;
function isLudic(plL:tpLl;maxIdx:nativeInt):boolean;
var
i,
n,LudicCnt,i : NativeUint;▼
//Mask read modify write reread
end;
isLudic := true;
end;
var
plL : tpLl;
begin
▲ n := 1;
// special case 1
n := 1;
Ll[0].dNum := 1;
plL := @Ll[0];
LudicCnt := 0;
repeat
inc(n);
If isLudic(plL,LudicCnt ) then
▲ isLucid := true;
▲ //check if n is 'hit' by a prior ludic number
▲ For i := 1 to LudicCnt do
▲ with Ll[i] do
▲ Begin
▲ dec(dCnt);
▲ IF dCnt = 0 then
▲ Begin
▲ dcnt := dNum;
▲ isLucid := false;
▲ BREAK
▲ end;
▲ end;
If isLucid then▼
Begin
inc(LudicCnt);
with
Begin
dNum := n;
dCnt := n;
end;
BREAK;
end;
until
end;
Line 1,396 ⟶ 1,413:
var
i,
chk :
Begin
// special case 1,3,7
writeln('Ludic triples below ',max);
write('(',ll[0].dNum,',',ll[2].dNum,',',ll[4].dNum,') ');
For i := 1 to High(Ll) do
Begin
Line 1,414 ⟶ 1,431:
end;
procedure LastLucid(var Ll:tLudicList;start,cnt: NativeUint);
var
limit,i : NativeUint;
Begin
dec(start);
▲ IF cnt >= length(Ll) then
cnt := limit;
writeln(i-cnt,'.th to ',i,'.th ludic number');▼
if start+cnt >limit then
For i := High(Ll)-cnt+1 to High(Ll)-1 do▼
start := limit-cnt;
write(Ll[i].dNum,',');▼
writeln(
▲ write(Ll[i+start].dNum,',');
writeln(Ll[start+cnt].dNum);
writeln;
end;
Line 1,430 ⟶ 1,450:
function CountLudic(var Ll:tLudicList;Limit: NativeUint):NativeUint;
var
i,res : NativeUint;
Begin
For i := 0 to High(Ll) do begin
IF Ll[i].dnum <= Limit then
inc(
else
BREAK;
CountLudic:= res;
end;
Line 1,443 ⟶ 1,464:
var
LudicList : tLudicList;
BEGIN
setlength(LudicList,maxLudicCnt);
firstN(LudicList,25);
writeln('There are ',CountLudic(LudicList,1000),' ludic numbers below 1000');
LastLucid(LudicList,2000,5);
LastLucid(LudicList,maxLudicCnt,5);
triples(LudicList,250);//all-> (LudicList,LudicList[High(LudicList)].dNum);
END.
{
1,2,3,5,7,11,13,17,23,25,29,37,41,43,47,53,61,67,71,77,83,89,91,97,107
There are 142 ludic numbers below 1000
21475,21481,21487,21493,21503,21511
1561291,1561301,1561307,1561313,1561333▼
▲1561243,1561291,1561301,1561307,1561313,1561333
Ludic triples below 250
(1,3,7) (5,7,11) (11,13,17) (23,25,29) (41,43,47) (173,175,179) (221,223,227) (233,235,239)
real 0m2.921s}</lang>
{{Output}}
<pre>
|