Strange unique prime triplets: Difference between revisions

Added 11l
m (Minor edit to Java code)
(Added 11l)
Line 8:
:* &nbsp; (stretch goal) &nbsp; Show the <u>count</u> (only) of all the triplets of strange unique primes in which &nbsp; &nbsp;&nbsp;'''n,&nbsp;m,'''&nbsp;and&nbsp;'''p'''&nbsp; &nbsp; are all less than &nbsp; '''1,000'''.
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>F primes_upto(limit)
V is_prime = [0B] * 2 [+] [1B] * (limit - 1)
L(n) 0 .< Int(limit ^ 0.5 + 1.5)
I is_prime[n]
L(i) (n * n .< limit + 1).step(n)
is_prime[i] = 0B
R enumerate(is_prime).filter((i, prime) -> prime).map((i, prime) -> i)
 
F strange_triplets(Int mx = 30)
[(Int, Int, Int)] r
V primes = Array(primes_upto(mx))
V primes3 = Set(primes_upto(3 * mx))
L(n) primes
V i = L.index
L(m) primes[i + 1 ..]
V j = L.index + i + 1
L(p) primes[j + 1 ..]
I n + m + p C primes3
r.append((n, m, p))
R r
 
L(n, m, p) strange_triplets()
print(‘#2: #2+#2+#2 = #.’.format(L.index + 1, n, m, p, n + m + p))
 
V mx = 1'000
print("\nIf n, m, p < #. finds #.".format(mx, sum(strange_triplets(mx).map(_ -> 1))))</lang>
 
{{out}}
<pre>
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
 
If n, m, p < 1000 finds 241580
</pre>
 
=={{header|ALGOL W}}==
Line 109 ⟶ 187:
Found 241580 strange unique prime triplets up to 1000
</pre>
 
=={{header|AWK}}==
<lang AWK>
1,481

edits