Jump to content

Strange unique prime triplets: Difference between revisions

(→‎{{header|ALGOL 68}}: Use ALGOL 68-primes)
Line 1,419:
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime`.
<lang jq>def count(s): reduce s as $x (null; .+1);
 
def task($n):
[2, (range(3;$n;2)|select(is_prime))]
| . as $p
| range(0; length) as $i
| range($i+1; length) as $j
| range($j+1; length) as $k
| [.[$i], .[$j], .[$k]]
| select( add| is_prime) ;
 
task(30),
"\nStretch goal: \(count(task(1000)))"</lang>
{{out}}
<pre>
[3,5,11]
[3,5,23]
[3,5,29]
[3,7,13]
[3,7,19]
[3,11,17]
[3,11,23]
[3,11,29]
[3,17,23]
[5,7,11]
[5,7,17]
[5,7,19]
[5,7,29]
[5,11,13]
[5,13,19]
[5,13,23]
[5,13,29]
[5,17,19]
[5,19,23]
[5,19,29]
[7,11,13]
[7,11,19]
[7,11,23]
[7,11,29]
[7,13,17]
[7,13,23]
[7,17,19]
[7,17,23]
[7,17,29]
[7,23,29]
[11,13,17]
[11,13,19]
[11,13,23]
[11,13,29]
[11,17,19]
[11,19,23]
[11,19,29]
[13,17,23]
[13,17,29]
[13,19,29]
[17,19,23]
[19,23,29]
 
Stretch goal: 241580
</pre>
=={{header|Julia}}==
<lang julia>using Primes
2,515

edits

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