Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
42
Task/Truncatable-primes/XPL0/truncatable-primes.xpl0
Normal file
42
Task/Truncatable-primes/XPL0/truncatable-primes.xpl0
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
code CrLf=9, IntOut=11;
|
||||
|
||||
func Prime(P); \Return true if P is a prime number
|
||||
int P; \(1 is not prime, but 2 is, etc.)
|
||||
int I;
|
||||
[if P<=1 then return false; \negative numbers are not prime
|
||||
for I:= 2 to sqrt(P) do
|
||||
if rem(P/I) = 0 then return false;
|
||||
return true;
|
||||
];
|
||||
|
||||
func RightTrunc(N); \Return largest right-truncatable prime < one million
|
||||
int N;
|
||||
int M;
|
||||
[for N:= 1_000_000-1 downto 2 do
|
||||
[M:= N;
|
||||
loop [if not Prime(M) then quit;
|
||||
M:= M/10;
|
||||
if rem(0) = 0 then quit; \no zeros allowed
|
||||
if M=0 then return N;
|
||||
];
|
||||
];
|
||||
];
|
||||
|
||||
func LeftTrunc(N); \Return largest left-truncatable prime < one million
|
||||
int N;
|
||||
int M, P;
|
||||
[for N:= 1_000_000-1 downto 2 do
|
||||
[M:= N;
|
||||
P:=100_000;
|
||||
loop [if not Prime(M) then quit;
|
||||
M:= rem(M/P);
|
||||
P:= P/10;
|
||||
if M<P then quit; \no zeros allowed
|
||||
if M=0 then return N;
|
||||
];
|
||||
];
|
||||
];
|
||||
|
||||
[IntOut(0, LeftTrunc); CrLf(0);
|
||||
IntOut(0, RightTrunc); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue