Strange unique prime triplets: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(7 intermediate revisions by 4 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}}
 
'''Solution'''
 
Definitions:
 
[[File:Fōrmulæ - Strange unique prime triplets 01.png]]
 
[[File:Fōrmulæ - Strange unique prime triplets 02.png]]
 
'''Test case 1. Find all triplets of strange unique primes in which n, m, and p are all less than 30'''
 
[[File:Fōrmulæ - Strange unique prime triplets 03.png]]
 
[[File:Fōrmulæ - Strange unique prime triplets 04.png]]
 
'''Test case 2. (Stretch goal). Show the count (only) of all the triplets of strange unique primes in which n, m, and p are all less than 1,000'''
 
[[File:Fōrmulæ - Strange unique prime triplets 05.png]]
 
[[File:Fōrmulæ - Strange unique prime triplets 06.png]]
 
[[File:Fōrmulæ - Strange unique prime triplets 07.png]]
 
=={{header|Go}}==
Line 1,424 ⟶ 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,604 ⟶ 1,677:
Stretch goal: 241580
</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Primes
Line 2,222 ⟶ 2,296:
 
If n, m, p < 1_000 finds 241_580</pre>
 
=={{header|Quackery}}==
<code>isprime</code> is defined at [[Primality by trial division#Quackery]].
 
<code>comb</code> is defined at [[Combinations#Quackery]].
 
<syntaxhighlight lang="Quackery"> [ dup size dip
[ witheach
[ over swap peek swap ] ]
nip pack ] is arrange ( [ [ --> [ )
 
[ 0 swap witheach + ] is sum ( [ --> n )
 
[] 30 times
[ i^ isprime if
[ i^ join ] ]
behead drop
3 over size comb
[] unrot
witheach
[ over swap arrange
dup sum
isprime not iff
drop done
nested swap dip join ]
drop
sortwith [ sum dip sum > ]
dup size echo
say " strange unique prime triplets found:"
cr cr
witheach
[ dup witheach
[ echo
i if say "+" ]
say " = " sum echo
cr ]</syntaxhighlight>
 
{{out}}
 
<pre>42 strange unique prime triplets found:
 
3+5+11 = 19
3+7+13 = 23
5+7+11 = 23
3+7+19 = 29
5+7+17 = 29
5+11+13 = 29
3+5+23 = 31
3+11+17 = 31
5+7+19 = 31
7+11+13 = 31
3+5+29 = 37
3+11+23 = 37
5+13+19 = 37
7+11+19 = 37
7+13+17 = 37
5+7+29 = 41
5+13+23 = 41
5+17+19 = 41
7+11+23 = 41
11+13+17 = 41
3+11+29 = 43
3+17+23 = 43
7+13+23 = 43
7+17+19 = 43
11+13+19 = 43
5+13+29 = 47
5+19+23 = 47
7+11+29 = 47
7+17+23 = 47
11+13+23 = 47
11+17+19 = 47
5+19+29 = 53
7+17+29 = 53
11+13+29 = 53
11+19+23 = 53
13+17+23 = 53
7+23+29 = 59
11+19+29 = 59
13+17+29 = 59
17+19+23 = 59
13+19+29 = 61
19+23+29 = 71</pre>
 
=={{header|Raku}}==
Line 2,408 ⟶ 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 2,902 ⟶ 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 2,982 ⟶ 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,482

edits