Ascending primes: Difference between revisions

→‎{{header|Ring}}: Rewrote code, removed warning
(→‎{{header|Ring}}: Rewrote code, removed warning)
Line 1,343:
 
=={{header|Ring}}==
<lang ring>show("ascending primes", sort(cending_primes(seq(1, 9))))
{{incorrect|Ring| <br> Many of the numbers shown do not have strictly ascending digits, e.g. all the ones starting with 9. <br> The single digit primes should also be included. }}
 
func show(title, itm)
<lang ring>
l = len(itm); ? "" + l + see" "" + ntitle + " :"
load "stdlibcore.ring"
for ni = 1 to limitl
see fmt(itm[i], 9)
if i % 5 = 0 and i < l? "" ok
next : ? ""
 
func seq(b, e)
limit = 1000
res = []; d = e - b
row = 0
s = d / fabs(d)
for i = b to e step s add(res, i) next
return res
 
func ispr(n)
for n = 1 to limit
if n flag< =2 return 0 ok
if n strn& 1 = string(0 return n) = 2 ok
if n if% 3 = 0 return isprime(n) = 13 ok
for ml = 1 to lensqrt(strnn)-1
for f = 5 to okl
if number(substr(strn,m)) > number(substr(strn,m+1))
if n % f = 0 or n % (f flag+ 2) = 10 return false ok
next : return ok1
next
if flag = 1
row++
see "" + n + " "
ok
if row % 10 = 0
see nl
ok
ok
next
</lang>
Output:
 
func cending_primes(digs)
11 13 17 19 23 29 31 37 41 43
cand = [0]
47 53 59 61 67 71 73 79 83 89
pr = ok[]
97 101 103 107 109 113 127 131 137 139
for i in digs
149 151 157 163 167 173 179 181 191 193
lcand = cand
197 199 211 223 227 229 233 239 241 251
for j in lcand
257 263 269 271 277 281 283 293 307 311
313 317 331 337 347 349 353v 359= 367j 373* 10 + i
if ispr(v) add(pr, v) ok
379 383 389 397 401 409 419 421 431 433
add(cand, v)
439 443 449 457 461 463 467 479 487 491
next
499 503 509 521 523 541 547 557 563 569
next
571 577 587 593 599 601 607 613 617 619
return pr
631 641 643 647 653 659 661 673 677 683
 
691 701 709 719 727 733 739 743 751 757
func fmt(x, l)
761 769 773 787 797 809 811 821 823 827
829 839 853res 857= 859" 863 877 881 883 887 " + x
return right(res, l)</lang>
907 911 919 929 937 941 947 953 967 971
{{out}}
977 983 991 997
<pre>100 ascending primes:
2 3 5 7 13
17 19 23 29 37
47 59 67 79 89
127 137 139 149 157
167 179 239 257 269
347 349 359 367 379
389 457 467 479 569
1237 1249 1259 1279 1289
1367 1459 1489 1567 1579
1789 2347 2357 2389 2459
2467 2579 2689 2789 3457
3467 3469 4567 4679 4789
5689 12347 12379 12457 12479
12569 12589 12689 13457 13469
13567 13679 13789 15679 23459
23567 23689 23789 25679 34589
34679 123457 123479 124567 124679
125789 134789 145679 234589 235679
235789 245789 345679 345689 1234789
1235789 1245689 1456789 12356789 23456789</pre>
 
=={{header|Ruby}}==