Prime numbers which contain 123: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: Use ALGOL 68-primes) |
|||
Line 284: | Line 284: | ||
Found 451 such primes under 1,000,000. |
Found 451 such primes under 1,000,000. |
||
</pre> |
</pre> |
||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
'''Works with gojq, the Go implementation of jq''' |
|||
For a suitable implementation of `is_prime`, see e.g. # [[Erd%C5%91s-primes#jq]]. |
|||
<lang jq>def count(stream): reduce stream as $i (0; .+1); |
|||
def digits: tostring | explode; |
|||
# Input: an upper bound, or `infinite` |
|||
def primes_with_123: |
|||
("123"| digits) as $d123 |
|||
| range(123; .; 2)) |
|||
| select( (digits | index($d123)) and is_prime); |
|||
100000 | primes_with_123, |
|||
(1000000 |
|||
| "\nThere are \(count(primes_with_123)) \"123\" primes less than \(.).")</lang> |
|||
{{out}} |
|||
(Abbreviated) |
|||
<pre> |
|||
1123 |
|||
1231 |
|||
1237 |
|||
8123 |
|||
... |
|||
81233 |
|||
81239 |
|||
89123 |
|||
91237 |
|||
98123 |
|||
There are 451 "123" primes less than 1000000. |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |