Primes with digits in nondecreasing order: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 5: | Line 5: | ||
Find all primes ('''n''') with their decimal digits in non-decreasing order, where '''n < 1,000''' |
Find all primes ('''n''') with their decimal digits in non-decreasing order, where '''n < 1,000''' |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Nim}} |
|||
<lang 11l>F is_prime(a) |
|||
I a == 2 |
|||
R 1B |
|||
I a < 2 | a % 2 == 0 |
|||
R 0B |
|||
L(i) (3 .. Int(sqrt(a))).step(2) |
|||
I a % i == 0 |
|||
R 0B |
|||
R 1B |
|||
F is_non_decreasing(=n) |
|||
V prev = 10 |
|||
L n != 0 |
|||
V d = n % 10 |
|||
I d > prev {R 0B} |
|||
prev = d |
|||
n I/= 10 |
|||
R 1B |
|||
V c = 0 |
|||
L(n) 1000 |
|||
I is_non_decreasing(n) & is_prime(n) |
|||
c++ |
|||
print(‘#3’.format(n), end' I c % 10 == 0 {"\n"} E ‘ ’) |
|||
print() |
|||
print(‘Found ’c‘ primes with digits in nondecreasing order’)</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 |
|||
Found 50 primes with digits in nondecreasing order |
|||
</pre> |
|||
=={{header|Action!}}== |
=={{header|Action!}}== |