Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Circular-primes/XPL0/circular-primes.xpl0
Normal file
43
Task/Circular-primes/XPL0/circular-primes.xpl0
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
func IsPrime(N); \Return 'true' if N > 2 is a prime number
|
||||
int N, I;
|
||||
[if (N&1) = 0 \even number\ then return false;
|
||||
for I:= 3 to sqrt(N) do
|
||||
[if rem(N/I) = 0 then return false;
|
||||
I:= I+1;
|
||||
];
|
||||
return true;
|
||||
];
|
||||
|
||||
func CircPrime(N0); \Return 'true' if N0 is a circular prime
|
||||
int N0, N, Digits, Rotation, I, R;
|
||||
[N:= N0;
|
||||
Digits:= 0; \count number of digits in N
|
||||
repeat Digits:= Digits+1;
|
||||
N:= N/10;
|
||||
until N = 0;
|
||||
N:= N0;
|
||||
for Rotation:= 0 to Digits-1 do
|
||||
[if not IsPrime(N) then return false;
|
||||
N:= N/10; \rotate least sig digit into high end
|
||||
R:= rem(0);
|
||||
for I:= 0 to Digits-2 do
|
||||
R:= R*10;
|
||||
N:= N+R;
|
||||
if N0 > N then \reject N0 if it has a smaller prime rotation
|
||||
return false;
|
||||
];
|
||||
return true;
|
||||
];
|
||||
|
||||
int Counter, N;
|
||||
[IntOut(0, 2); ChOut(0, ^ ); \show first circular prime
|
||||
Counter:= 1;
|
||||
N:= 3; \remaining primes are odd
|
||||
loop [if CircPrime(N) then
|
||||
[IntOut(0, N); ChOut(0, ^ );
|
||||
Counter:= Counter+1;
|
||||
if Counter >= 19 then quit;
|
||||
];
|
||||
N:= N+2;
|
||||
];
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue