Strange unique prime triplets: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
(Reworded. Is this OK?)
Line 1: Line 1:
{{Draft task}}
{{Draft task}}

Integers n, m and p are strange primes if n, m and p are prime and the sum=n+m+p is also prime.


;Task:
;Task:
The n,m,p are strange numbers if n,m,p are primes and sum=n+m+p also prime.
Find all triplets of strange primes in which n, m, and p are all less than 30.
<br>Let 0 < n,m,p < 30


=={{header|Ring}}==
=={{header|Ring}}==

Revision as of 10:51, 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 primes if n, m and p are prime and the sum=n+m+p is also prime.

Task

Find all triplets of strange primes in which n, m, and p are all less than 30.

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 = " + sum + nl
           ok
       next
   next

next

see "done..." + nl </lang>

Output:
working...
the strange primes are:
1: 3 5 11 sum = 19
2: 3 5 23 sum = 31
3: 3 5 29 sum = 37
4: 3 7 13 sum = 23
5: 3 7 19 sum = 29
6: 3 11 17 sum = 31
7: 3 11 23 sum = 37
8: 3 11 29 sum = 43
9: 3 17 23 sum = 43
10: 5 7 11 sum = 23
11: 5 7 17 sum = 29
12: 5 7 19 sum = 31
13: 5 7 29 sum = 41
14: 5 11 13 sum = 29
15: 5 13 19 sum = 37
16: 5 13 23 sum = 41
17: 5 13 29 sum = 47
18: 5 17 19 sum = 41
19: 5 19 23 sum = 47
20: 5 19 29 sum = 53
21: 7 11 13 sum = 31
22: 7 11 19 sum = 37
23: 7 11 23 sum = 41
24: 7 11 29 sum = 47
25: 7 13 17 sum = 37
26: 7 13 23 sum = 43
27: 7 17 19 sum = 43
28: 7 17 23 sum = 47
29: 7 17 29 sum = 53
30: 7 23 29 sum = 59
31: 11 13 17 sum = 41
32: 11 13 19 sum = 43
33: 11 13 23 sum = 47
34: 11 13 29 sum = 53
35: 11 17 19 sum = 47
36: 11 19 23 sum = 53
37: 11 19 29 sum = 59
38: 13 17 23 sum = 53
39: 13 17 29 sum = 59
40: 13 19 29 sum = 61
41: 17 19 23 sum = 59
42: 19 23 29 sum = 71
done...