Primes whose sum of digits is 25: Difference between revisions

m (Peak moved page Primes which sum of digits is 25 to Primes whose sum of digits is 25: acceptable English)
Line 1,193:
3769 3877 3967 4597 4759
4957 4993</pre>
 
=={{header|jq}}==
'''Works with [[#jq|jq]] '''<br>
'''Works with gojq, the Go implementation of jq'''
 
The stretch goal is currently beyond the practical capabilities of both the C and Go-based implementations of jq,
so only a simple solution to the primary task is shown here.
 
A suitable definition of `is_prime` may be found at [[Erd%C5%91s-primes#jq]] and is therefore not repeated here.
 
'''Preliminaries'''
<lang jq>def digits: tostring | explode | map( [.]|implode|tonumber);
 
def emit_until(cond; stream): label $out | stream | if cond then break $out else . end;</lang>
'''The Task'''
<lang jq># Output: primes whose decimal representation has no 0s and whose sum of digits is $sum > 2
def task($sum):
# Input: array of digits
def nozeros: select(all(.[]; . != 0));
range(3;infinite;2)
| select(digits | (.[-1] != 5 and nozeros and (add == $sum)) )
| select(is_prime);
emit_until(. >= 5000; task(25) )</lang>
{{out}}
<pre>
997
1699
1789
1879
1987
2689
2797
2887
3499
3697
3769
3877
3967
4597
4759
4957
4993
</pre>
 
=={{header|Julia}}==
2,442

edits