Strange unique prime triplets: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: added a REXX stub. |
added highlighting and a stretch goal to the draft task. |
||
Line 1: | Line 1: | ||
{{Draft task}} |
{{Draft task}} |
||
Integers n, m and p are strange unique primes if n, m and p are unique primes and the sum |
Integers '''n, m,''' and '''p''' are ''strange unique primes'' if '''n, m,''' and '''p''' are unique primes, and the sum of '''n + m + p''' is also prime. |
||
;Task: |
;Task: |
||
Find all triplets of strange unique primes in which n, m, and p are all less than 30. |
:* Find all triplets of strange unique primes in which '''n, m,''' and '''p''' are all less than '''30'''. |
||
:* (stretch goal) Show the <u>count</u> (only) of all the triplets of strange unique primes in which '''n, m,''' and '''p''' are all less than '''1,000'''. |
|||
<br><br> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
Revision as of 12:58, 10 March 2021
Strange unique prime triplets is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Integers n, m, and p are strange unique primes if n, m, and p are unique primes, and the sum of n + m + p is also prime.
- Task
-
- Find all triplets of strange unique primes in which n, m, and p are all less than 30.
- (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.
Python
Using sympy.primerange.
<lang python>from sympy import primerange
def strange_triplets(mx: int = 30) -> None:
primes = list(primerange(0, mx)) primes3 = set(primerange(0, 3 * mx)) c = 0 for i, n in enumerate(primes): for j, m in enumerate(primes[i + 1:], i + 1): for p in primes[j + 1:]: if n + m + p in primes3: c += 1 print(f"{c:2}: {n:2}+{m:2}+{p:2} = {n + m + p}")
strange_triplets()</lang>
- Output:
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
REXX
<lang rexx></lang>
Ring
<lang ring> load "stdlib.ring"
num = 0 limit = 30
see "working..." + nl see "the strange primes are:" + nl
for n = 1 to limit
for m = n+1 to limit for p = m+1 to limit sum = n+m+p if isprime(sum) and isprime(n) and isprime(m) and isprime(p) num = num + 1 see "" + num + ": " + n + "+" + m + "+" + p + " = " + sum + nl ok next next
next
see "done..." + nl </lang>
- Output:
working... the strange primes are: 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 done...