Jump to content

Primes with digits in nondecreasing order: Difference between revisions

Added 11l
(Added solution for Action!)
(Added 11l)
Line 5:
Find all primes   ('''n''')   with their decimal digits in non-decreasing order,   where   '''n   <   1,000'''
<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!}}==
1,481

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.