Smarandache prime-digital sequence: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: Added Ruby) |
Catskill549 (talk | contribs) |
||
Line 56: | Line 56: | ||
100th item of this sequence is 33223 |
100th item of this sequence is 33223 |
||
1000th item of this sequence is 3273527 |
1000th item of this sequence is 3273527 |
||
</pre> |
|||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f SMARANDACHE_PRIME-DIGITAL_SEQUENCE.AWK |
|||
BEGIN { |
|||
limit = 25 |
|||
printf("1-%d:",limit) |
|||
while (1) { |
|||
if (is_prime(++n)) { |
|||
if (all_digits_prime(n) == 1) { |
|||
if (++count <= limit) { |
|||
printf(" %d",n) |
|||
} |
|||
if (count == 100) { |
|||
printf("\n%d: %d\n",count,n) |
|||
break |
|||
} |
|||
} |
|||
} |
|||
} |
|||
exit(0) |
|||
} |
|||
function all_digits_prime(n, i) { |
|||
for (i=1; i<=length(n); i++) { |
|||
if (!is_prime(substr(n,i,1))) { |
|||
return(0) |
|||
} |
|||
} |
|||
return(1) |
|||
} |
|||
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> |
|||
1-25: 2 3 5 7 23 37 53 73 223 227 233 257 277 337 353 373 523 557 577 727 733 757 773 2237 2273 |
|||
100: 33223 |
|||
</pre> |
</pre> |
||