Primes with digits in nondecreasing order: Difference between revisions

m (→‎{{header|Ring}}: cleaned up)
Line 60:
 
Found 50 non-descending primes up to 1000
</pre>
=={{header|AWK}}==
<lang AWK>
# syntax: GAWK -f PRIMES_WITH_DIGITS_IN_NONDECREASING_ORDER.AWK
BEGIN {
start = 1
stop = 1000
for (i=start; i<=stop; i++) {
if (is_prime(i)) {
flag = 1
for (j=1; j<length(i); j++) {
if (substr(i,j,1) > substr(i,j+1,1)) {
flag = 0
}
}
if (flag == 1) {
printf("%4d%1s",i,++count%10?"":"\n")
}
}
}
printf("\nPrimes with digits in nondecreasing order %d-%d: %d\n",start,stop,count)
exit(0)
}
function is_prime(x, i) {
if (x <= 1) {
return(0)
}
for (i=2; i<=int(sqrt(x)); i++) {
if (x % i == 0) {
return(0)
}
}
return(1)
}
</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
 
Primes with digits in nondecreasing order 1-1000: 50
</pre>
 
477

edits