Primes whose sum of digits is 25: Difference between revisions

m
(Add Zig solution)
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by 2 users not shown)
Line 1,107:
3967 4597 4759 4957
4993</pre>
 
=={{header|J}}==
<syntaxhighlight lang="j"> (#~ 25 = +/@("."0@":)"0) p: i. _1 p: 5000
997 1699 1789 1879 1987 2689 2797 2887 3499 3697 3769 3877 3967 4597 4759 4957 4993</syntaxhighlight>
 
=={{header|Java}}==
Line 2,123 ⟶ 2,127:
time = 30 mins
done...
</pre>
 
=={{header|RPL}}==
<code>∑DIGITS</code> is defined at [[Sum digits of an integer#RPL|Sum digits of an integer]]
≪ { } 799 <span style="color:grey">@ 799 is the smallest integer whose digits sum equals 25, and is not prime : 799 = 47 * 17</span>
'''DO'''
NEXTPRIME
IF DUP <span style="color:blue">∑DIGITS</span> 25 == '''THEN''' SWAP OVER + SWAP '''END'''
'''UNTIL''' DUP 5000 > '''END'''
DROP
≫ '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: {997 1699 1789 1879 1987 2689 2797 2887 3499 3697 3769 3877 3967 4597 4759 4957 4993}
</pre>
 
Line 2,199 ⟶ 2,217:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="wren">import "./math" for Int
{{libheader|Wren-seq}}
<syntaxhighlight lang="ecmascript">import "./mathfmt" for IntFmt
import "/fmt" for Fmt
import "/seq" for Lst
 
var sumDigits = Fn.new { |n|
Line 2,219 ⟶ 2,235:
}
System.print("The %(primes25.count) primes under 5,000 whose digits sum to 25 are:")
for (chunk in Lst.chunks(primes25, 6)) Fmt.printtprint("$,6d", chunkprimes25, 6)</syntaxhighlight>
 
{{out}}
Line 2,232 ⟶ 2,248:
{{libheader|Wren-gmp}}
Run time is about 25.5 seconds.
<syntaxhighlight lang="ecmascriptwren">import "./gmp" for Mpz
import "./fmt" for Fmt
 
9,476

edits