Strange unique prime triplets: Difference between revisions

m
m (→‎{{header|Quackery}}: corrected output)
m (→‎{{header|Wren}}: Minor tidy)
 
(4 intermediate revisions by 2 users not shown)
Line 339:
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">findTriplets: function [upTo][
results: []
Line 936 ⟶ 935:
74588542
</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: formatting io kernel math math.combinatorics math.primes
Line 1,202:
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Strange_unique_prime_triplets}}
 
Line 1,446 ⟶ 1,445:
{{out}}
Same as 'basic' version.
 
=={{header|J}}==
<syntaxhighlight lang="j">cb=. ;@:({. <@,. @\.)}.
comb3=. ]cb cb
triplets=. (#~ 1 p: +/"1)@comb3@(i.&.(p:inv)"0)</syntaxhighlight>
{{out}}
<pre> triplets 30
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
 
#@triplets 30 1000
42 241580</pre>
 
=={{header|Java}}==
Line 1,626 ⟶ 1,677:
Stretch goal: 241580
</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Primes
Line 2,246 ⟶ 2,298:
 
=={{header|Quackery}}==
 
<code>isprime</code> is defined at [[Primality by trial division#Quackery]].
 
Line 2,514 ⟶ 2,565:
done...
 
</pre>
 
=={{header|RPL}}==
{{works with|HP|49}}
« { }
'''DO''' SWAP OVER + SWAP NEXTPRIME
'''UNTIL''' DUP 30 > '''END'''
DROP DUP SIZE
→ primes size
« { }
1 size 2 - '''FOR''' m
m 1 + size 1 - '''FOR''' n
n 1 + size '''FOR''' p
primes m GET primes n GET primes p GET
'''IF''' 3 DUPN + + ISPRIME? '''THEN'''
ROT "+" + ROT + "+" + SWAP + +
'''ELSE''' 3 DROPN '''END'''
'''NEXT NEXT NEXT'''
DUP SIZE
» » '<span style="color:blue">TASK</span>' STO
 
{{out}}
<pre>
2: { "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" }
1: 42.
</pre>
 
Line 3,008 ⟶ 3,084:
{{libheader|Wren-iterate}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./iterate" for Stepped
import "./fmt" for Fmt
 
var strangePrimes = Fn.new { |n, countOnly|
Line 3,088 ⟶ 3,164:
===Faster===
The following version uses a prime sieve and is about 17 times faster than the 'basic' version.
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./fmt" for Fmt
 
var max = 1000
9,477

edits