Jordan-Pólya numbers: Difference between revisions

Content added Content deleted
(Added XPL0 example.)
(Faster XPL0 example.)
Line 118: Line 118:


=={{header|XPL0}}==
=={{header|XPL0}}==
Simple-minded brute force. 32 seconds on Pi4. No bonus (yet).
Simple-minded brute force. 20 seconds on Pi4. No bonus.
<syntaxhighlight lang "XPL0">int Factorials(13);
<syntaxhighlight lang "XPL0">int Factorials(1+12);


func IsJPNum(N0);
func IsJPNum(N0);
int N0;
int N0;
int N, Limit, I, Q;
int N, Limit, I, Q;
[Limit:= 7; N:= N0;
[Limit:= 7;
N:= N0;
loop [I:= Limit;
loop [I:= Limit;
loop [Q:= N / Factorials(I);
loop [Q:= N / Factorials(I);
Line 143: Line 144:


int F, N, C, SN;
int F, N, C, SN;
[Factorials(0):= 1;
[F:= 1;
F:= 1;
for N:= 1 to 12 do
for N:= 1 to 12 do
[F:= F*N;
[F:= F*N;
Line 151: Line 151:
Text(0, "First 50 Jordan-Polya numbers:^m^j");
Text(0, "First 50 Jordan-Polya numbers:^m^j");
Format(5, 0);
Format(5, 0);
RlOut(0, 1.); \handle odd number exception
N:= 1; C:= 0;
C:= 1; N:= 2;
loop [if IsJPNum(N) then
loop [if IsJPNum(N) then
[C:= C+1;
[C:= C+1;
Line 160: Line 161:
SN:= N;
SN:= N;
];
];
N:= N+1;
N:= N+2;
if N >= 100_000_000 then quit;
if N >= 100_000_000 then quit;
];
];