Ludic numbers: Difference between revisions

Content added Content deleted
({{header|Pascal}})
Line 1,312: Line 1,312:
}
}
</lang>
</lang>

{{Output}}
{{Output}}
<pre>
<pre>
Line 1,325: Line 1,324:
Ludic Triplets below 250:
Ludic Triplets 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)
(1 3 7) (5 7 11) (11 13 17) (23 25 29) (41 43 47) (173 175 179) (221 223 227) (233 235 239)
</pre>

=={{header|Pascal}}==
Inspired by "rotors" of perl 6 .
Runtime nearly quadratic: maxLudicCnt = 10000 -> 0.04 s =>maxLudicCnt= 100000 -> 4.88 s
There is much space for improvement.Analog to prime wheels 2,3 -> +2+4,+2+4,+2+4 so only 2 of 6 numbers are to check.
The rotors can be grouped/listed together in order of their remaining cnt values. <10, <100, < 1000,< 10000 to reduce the checks of a special rotor.
<lang pascal>program lucid;
{$IFDEF FPC}
{$MODE objFPC}
{$ENDIF}

const
maxLudicCnt = 2005; //must be > 1
type
tDelta = record
dNum : LongInt;
dCnt : LongInt;
end;
tLudicList = array of tDelta;

procedure getLudic(var Ll:tLudicList);
var
n,LudicCnt,i : NativeUint;
isLucid : boolean;
begin
n := 1;
// special case 1
Ll[0].dNum := 1;
LudicCnt := 0;

repeat
inc(n);
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;
// a new ludic number found?
If isLucid then
Begin
inc(LudicCnt);
with Ll[LudicCnt] do
Begin
dNum := n;
dCnt := n;
end;
end;
until LudicCnt >= High(LL);
end;

procedure firstN(var Ll:tLudicList;cnt: NativeUint);
var
i : NativeInt;
Begin
writeln('First ',cnt,' ludic numbers:');
For i := 0 to cnt-2 do
write(Ll[i].dNum,',');
writeln(Ll[cnt-1].dNum);
end;

procedure triples(var Ll:tLudicList;max: NativeUint);
var
i,
chk : NativeInt;

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
chk := ll[i].dNum;
If chk> max then
break;
If (ll[i+2].dNum = chk+6) AND (ll[i+1].dNum = chk+2) then
write('(',ll[i].dNum,',',ll[i+1].dNum,',',ll[i+2].dNum,') ');
end;
writeln;
writeln;
end;

procedure LastLucid(var Ll:tLudicList;cnt: NativeUint);
var
i : NativeUint;
Begin
IF cnt >= length(Ll) then
cnt := High(Ll);
i:= length(Ll);
writeln(i-cnt,'.th to ',i,'.th ludic number');
For i := High(Ll)-cnt+1 to High(Ll)-1 do
write(Ll[i].dNum,',');
writeln(Ll[High(Ll)].dNum);
writeln;
end;

function CountLudic(var Ll:tLudicList;Limit: NativeUint):NativeUint;
var
i : NativeUint;
Begin
result := 0;
For i := 0 to High(Ll) do begin
IF Ll[i].dnum <= Limit then
inc(result)
else
BREAK;
end;

end;
var
LudicList : tLudicList;

BEGIN
setlength(LudicList,maxLudicCnt);
getLudic(LudicList);
firstN(LudicList,25);
writeln('There are ',CountLudic(LudicList,1000),' ludic numbers below 1000');
LastLucid(LudicList,5);
triples(LudicList,250);//all-> (LudicList,LudicList[High(LudicList)].dNum);
END.
(*
//maxLudicCnt = 100000
...
99995.th to 100000.th ludic numbers
1561291,1561301,1561307,1561313,1561333
*)
</lang>
{{Output}}
<pre>
First 25 ludic numbers:
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
2000.th to 2005.th ludic number
21481,21487,21493,21503,21511

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)
</pre>
</pre>