Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
59
Task/Unprimeable-numbers/XPL0/unprimeable-numbers.xpl0
Normal file
59
Task/Unprimeable-numbers/XPL0/unprimeable-numbers.xpl0
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
func IsPrime(N); \Return 'true' if N is prime
|
||||
int N, I;
|
||||
[if N <= 2 then return N = 2;
|
||||
if (N&1) = 0 then \even >2\ return false;
|
||||
for I:= 3 to sqrt(N) do
|
||||
[if rem(N/I) = 0 then return false;
|
||||
I:= I+1;
|
||||
];
|
||||
return true;
|
||||
];
|
||||
|
||||
func Unprimeable(N); \Return 'true' if N is unprimeable
|
||||
int N, I, J, Len, D, SD;
|
||||
char Num(10);
|
||||
[I:= 0; \take N apart
|
||||
repeat N:= N/10;
|
||||
Num(I):= rem(0);
|
||||
I:= I+1;
|
||||
until N = 0;
|
||||
Len:= I; \number of digits in N (length)
|
||||
for J:= 0 to Len-1 do
|
||||
[SD:= Num(J); \save digit
|
||||
for D:= 0 to 9 do \replace with all digits
|
||||
[Num(J):= D;
|
||||
N:= 0; \rebuild N
|
||||
for I:= Len-1 downto 0 do
|
||||
N:= N*10 + Num(I);
|
||||
if IsPrime(N) then return false;
|
||||
];
|
||||
Num(J):= SD; \restore saved digit
|
||||
];
|
||||
return true;
|
||||
];
|
||||
|
||||
int C, N, D;
|
||||
[Text(0, "First 35 unprimeables:^m^j");
|
||||
C:= 0;
|
||||
N:= 100;
|
||||
loop [if Unprimeable(N) then
|
||||
[C:= C+1;
|
||||
if C <= 35 then
|
||||
[IntOut(0, N); ChOut(0, ^ )];
|
||||
if C = 600 then quit;
|
||||
];
|
||||
N:= N+1;
|
||||
];
|
||||
Text(0, "^m^j600th unprimeable: ");
|
||||
IntOut(0, N); CrLf(0);
|
||||
for D:= 0 to 9 do
|
||||
[IntOut(0, D); Text(0, ": ");
|
||||
N:= 100 + D;
|
||||
loop [if Unprimeable(N) then
|
||||
[IntOut(0, N); CrLf(0);
|
||||
quit;
|
||||
];
|
||||
N:= N+10;
|
||||
];
|
||||
];
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue