Unprimeable numbers: Difference between revisions

Added XPL0 example.
(→‎{{header|ALGOL 68}}: Corrected comment)
(Added XPL0 example.)
Line 3,292:
8 is: 208
9 is: 212,159
</pre>
 
=={{header|XPL0}}==
<lang XPL0>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;
];
];
]</lang>
 
{{out}}
<pre>
First 35 unprimeables:
200 204 206 208 320 322 324 325 326 328 510 512 514 515 516 518 530 532 534 535 536 538 620 622 624 625 626 628 840 842 844 845 846 848 890
600th unprimeable: 5242
0: 200
1: 595631
2: 322
3: 1203623
4: 204
5: 325
6: 206
7: 872897
8: 208
9: 212159
</pre>
 
772

edits