Jordan-Pólya numbers: Difference between revisions
Content added Content deleted
(Created a new draft task and added a Wren example.) |
(Added XPL0 example.) |
||
Line 115: | Line 115: | ||
The 3,800th Jordan-Pólya number is : 7,213,895,789,838,336 |
The 3,800th Jordan-Pólya number is : 7,213,895,789,838,336 |
||
= (4!)⁸ x (2!)¹⁶ |
= (4!)⁸ x (2!)¹⁶ |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
Simple-minded brute force. 32 seconds on Pi4. No bonus (yet). |
|||
<syntaxhighlight lang "XPL0">int Factorials(13); |
|||
func IsJPNum(N0); |
|||
int N0; |
|||
int N, Limit, I, Q; |
|||
[Limit:= 7; N:= N0; |
|||
loop [I:= Limit; |
|||
loop [Q:= N / Factorials(I); |
|||
if rem(0) = 0 then |
|||
[if Q = 1 then return true; |
|||
N:= Q; |
|||
] |
|||
else I:= I-1; |
|||
if I = 1 then |
|||
[if Limit = 1 then return false; |
|||
Limit:= Limit-1; |
|||
N:= N0; |
|||
quit; |
|||
] |
|||
]; |
|||
]; |
|||
]; |
|||
int F, N, C, SN; |
|||
[Factorials(0):= 1; |
|||
F:= 1; |
|||
for N:= 1 to 12 do |
|||
[F:= F*N; |
|||
Factorials(N):= F; |
|||
]; |
|||
Text(0, "First 50 Jordan-Polya numbers:^m^j"); |
|||
Format(5, 0); |
|||
N:= 1; C:= 0; |
|||
loop [if IsJPNum(N) then |
|||
[C:= C+1; |
|||
if C <= 50 then |
|||
[RlOut(0, float(N)); |
|||
if rem(C/10) = 0 then CrLf(0); |
|||
]; |
|||
SN:= N; |
|||
]; |
|||
N:= N+1; |
|||
if N >= 100_000_000 then quit; |
|||
]; |
|||
Text(0, "^m^jThe largest Jordan-Polya number before 100 million: "); |
|||
IntOut(0, SN); CrLf(0); |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
First 50 Jordan-Polya numbers: |
|||
1 2 4 6 8 12 16 24 32 36 |
|||
48 64 72 96 120 128 144 192 216 240 |
|||
256 288 384 432 480 512 576 720 768 864 |
|||
960 1024 1152 1296 1440 1536 1728 1920 2048 2304 |
|||
2592 2880 3072 3456 3840 4096 4320 4608 5040 5184 |
|||
The largest Jordan-Polya number before 100 million: 99532800 |
|||
</pre> |
</pre> |