Strange unique prime triplets: Difference between revisions

Added Wren
m (→‎{{header|REXX}}: added wordage to the output texts to show more information.)
(Added Wren)
Line 347:
done...
 
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-trait}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int
import "/trait" for Stepped
import "/fmt" for Fmt
 
var strangePrimes = Fn.new { |n, countOnly|
var c = 0
var s
for (i in Stepped.new(3..n-4, 2)) {
if (Int.isPrime(i)) {
for (j in Stepped.new(i+2..n-2, 2)) {
if (Int.isPrime(j)) {
for (k in Stepped.new(j+2..n, 2)) {
if (Int.isPrime(k) && Int.isPrime(s = i + j + k)) {
c = c + 1
if (!countOnly) Fmt.print("$2d: $2d + $2d + $2d = $2d", c, i, j, k, s)
}
}
}
}
}
}
return c
}
 
System.print("Unique prime triples under 30 which sum to a prime:")
strangePrimes.call(29, false)
var c = strangePrimes.call(999, true)
Fmt.print("\nThere are $,d unique prime triples under 1,000 which sum to a prime.", c)</lang>
 
{{out}}
<pre>
Unique prime triples under 30 which sum to a prime:
1: 3 + 5 + 11 = 19
2: 3 + 5 + 23 = 31
3: 3 + 5 + 29 = 37
4: 3 + 7 + 13 = 23
5: 3 + 7 + 19 = 29
6: 3 + 11 + 17 = 31
7: 3 + 11 + 23 = 37
8: 3 + 11 + 29 = 43
9: 3 + 17 + 23 = 43
10: 5 + 7 + 11 = 23
11: 5 + 7 + 17 = 29
12: 5 + 7 + 19 = 31
13: 5 + 7 + 29 = 41
14: 5 + 11 + 13 = 29
15: 5 + 13 + 19 = 37
16: 5 + 13 + 23 = 41
17: 5 + 13 + 29 = 47
18: 5 + 17 + 19 = 41
19: 5 + 19 + 23 = 47
20: 5 + 19 + 29 = 53
21: 7 + 11 + 13 = 31
22: 7 + 11 + 19 = 37
23: 7 + 11 + 23 = 41
24: 7 + 11 + 29 = 47
25: 7 + 13 + 17 = 37
26: 7 + 13 + 23 = 43
27: 7 + 17 + 19 = 43
28: 7 + 17 + 23 = 47
29: 7 + 17 + 29 = 53
30: 7 + 23 + 29 = 59
31: 11 + 13 + 17 = 41
32: 11 + 13 + 19 = 43
33: 11 + 13 + 23 = 47
34: 11 + 13 + 29 = 53
35: 11 + 17 + 19 = 47
36: 11 + 19 + 23 = 53
37: 11 + 19 + 29 = 59
38: 13 + 17 + 23 = 53
39: 13 + 17 + 29 = 59
40: 13 + 19 + 29 = 61
41: 17 + 19 + 23 = 59
42: 19 + 23 + 29 = 71
 
There are 241,580 unique prime triples under 1,000 which sum to a prime.
</pre>
9,488

edits