Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Ascending-primes/XPL0/ascending-primes-1.xpl0
Normal file
34
Task/Ascending-primes/XPL0/ascending-primes-1.xpl0
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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 Ascending(N); \Return 'true' if digits are ascending
|
||||
int N, D;
|
||||
[N:= N/10;
|
||||
D:= rem(0);
|
||||
while N do
|
||||
[N:= N/10;
|
||||
if rem(0) >= D then return false;
|
||||
D:= rem(0);
|
||||
];
|
||||
return true;
|
||||
];
|
||||
|
||||
int Cnt, N;
|
||||
[Cnt:= 0;
|
||||
Format(9, 0);
|
||||
for N:= 2 to 123_456_789 do
|
||||
if Ascending(N) then
|
||||
if IsPrime(N) then
|
||||
[RlOut(0, float(N));
|
||||
Cnt:= Cnt+1;
|
||||
if rem(Cnt/10) = 0 then CrLf(0);
|
||||
];
|
||||
]
|
||||
25
Task/Ascending-primes/XPL0/ascending-primes-2.xpl0
Normal file
25
Task/Ascending-primes/XPL0/ascending-primes-2.xpl0
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
include xpllib; \provides IsPrime and Sort
|
||||
|
||||
int I, N, Mask, Digit, A(512), Cnt;
|
||||
[for I:= 0 to 511 do
|
||||
[N:= 0; Mask:= I; Digit:= 1;
|
||||
while Mask do
|
||||
[if Mask&1 then
|
||||
N:= N*10 + Digit;
|
||||
Mask:= Mask>>1;
|
||||
Digit:= Digit+1;
|
||||
];
|
||||
A(I):= N;
|
||||
];
|
||||
Sort(A, 512);
|
||||
Cnt:= 0;
|
||||
Format(9, 0);
|
||||
for I:= 1 to 511 do \skip empty set
|
||||
[N:= A(I);
|
||||
if IsPrime(N) then
|
||||
[RlOut(0, float(N));
|
||||
Cnt:= Cnt+1;
|
||||
if rem(Cnt/10) = 0 then CrLf(0);
|
||||
];
|
||||
];
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue