Primes with digits in nondecreasing order: Difference between revisions

Added XPL0 example.
(Added Go)
(Added XPL0 example.)
Line 1,155:
 
50 such primes found.
</pre>
 
=={{header|XPL0}}==
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number
int N, I;
[if N <= 1 then return false;
for I:= 2 to sqrt(N) do
if rem(N/I) = 0 then return false;
return true;
];
 
func Nondecreasing(N);
\Return 'true' if N has left-to-right nondecreasing digits
\Or return 'true' if N has right-to-left nonincreasing digits
int N, D, D0;
[N:= N/10;
D0:= rem(0);
while N do
[N:= N/10;
D:= rem(0);
if D > D0 then return false;
D0:= D;
];
return true;
];
 
int Count, N;
[Count:= 0;
for N:= 0 to 1000-1 do
if IsPrime(N) and Nondecreasing(N) then
[IntOut(0, N);
Count:= Count+1;
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\);
];
CrLf(0);
IntOut(0, Count);
Text(0, " primes found with nondecreasing digits below 1000.
");
]</lang>
 
{{out}}
<pre>
2 3 5 7 11 13 17 19 23 29
37 47 59 67 79 89 113 127 137 139
149 157 167 179 199 223 227 229 233 239
257 269 277 337 347 349 359 367 379 389
449 457 467 479 499 557 569 577 599 677
 
50 primes found with nondecreasing digits below 1000.
</pre>
772

edits