Strange unique prime triplets: Difference between revisions

Content added Content deleted
(added highlighting and a stretch goal to the draft task.)
m (→‎{{header|REXX}}: added the computer programming language REXX.)
Line 72:
 
=={{header|REXX}}==
<lang rexx>/*REXX pgm lists triple strange primes (<HI) where the sum of the primes sum is a prime,*/
<lang rexx></lang>
parse arg hi . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 30 /*Not specified? Then use the default.*/
tell= hi>0; hi= abs(hi); hi= hi - 1 /*use the absolute value of HI. */
if tell>0 then say 'list of unique strange (three) primes that sum to a prime:'
call genP /*build array of semifores for primes. */
finds= 0 /*The number of strange primes (so far)*/
say
do m=2 to hi; if \!.m then iterate
do n=m+1 to hi; if \!.n then iterate
mn= m + n /*compute a partial sum for deep loops.*/
do p=n+1 to hi; if \!.p then iterate
sum= mn + p
if \!.sum then iterate /*Is the sum a prime? No, skip it. */
finds= finds + 1 /*bump the number of "strange" primes. */
if tell then say right(m, w+9) right(n, w) right(p, w) ,
' sum to: ' right(sum, w)
end /*p*/
end /*n*/
end /*m*/
say
say 'Found ' commas(finds) " unique strange primes which sum to a prime," ,
" each triple numbers are < " commas(hi+1).
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: !.= 0; w= length(hi) /*placeholders for primes; width of #'s*/
@.1=2; @.2=3; @.3=5; @.4=7; @.5=11 /*define some low primes. */
!.2=1; !.3=1; !.5=1; !.7=1; !.11=1 /* " " " " flags. */
#=5; s.#= @.# **2 /*number of primes so far; prime². */
/* [↓] generate more primes ≤ high.*/
do j=@.#+2 by 2 for hi*3%2 /*find odd primes from here on. */
parse var j '' -1 _; if _==5 then iterate /*J divisible by 5? (right dig)*/
if j// 3==0 then iterate /*" " " 3? */
if j// 7==0 then iterate /*" " " 7? */
/* [↑] the above five lines saves time*/
do k=5 while s.k<=j /* [↓] divide by the known odd primes.*/
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/
return</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
list of unique strange (three) primes that sum to a prime:
 
3 5 11 sum to: 19
3 5 23 sum to: 31
3 5 29 sum to: 37
3 7 13 sum to: 23
3 7 19 sum to: 29
3 11 17 sum to: 31
3 11 23 sum to: 37
3 11 29 sum to: 43
3 17 23 sum to: 43
5 7 11 sum to: 23
5 7 17 sum to: 29
5 7 19 sum to: 31
5 7 29 sum to: 41
5 11 13 sum to: 29
5 13 19 sum to: 37
5 13 23 sum to: 41
5 13 29 sum to: 47
5 17 19 sum to: 41
5 19 23 sum to: 47
5 19 29 sum to: 53
7 11 13 sum to: 31
7 11 19 sum to: 37
7 11 23 sum to: 41
7 11 29 sum to: 47
7 13 17 sum to: 37
7 13 23 sum to: 43
7 17 19 sum to: 43
7 17 23 sum to: 47
7 17 29 sum to: 53
7 23 29 sum to: 59
11 13 17 sum to: 41
11 13 19 sum to: 43
11 13 23 sum to: 47
11 13 29 sum to: 53
11 17 19 sum to: 47
11 19 23 sum to: 53
11 19 29 sum to: 59
13 17 23 sum to: 53
13 17 29 sum to: 59
13 19 29 sum to: 61
17 19 23 sum to: 59
19 23 29 sum to: 71
 
Found 42 unique strange primes which sum to a prime, each triple numbers are < 30.
</pre>
 
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> -1000 </tt>}}
<pre>
Found 241,580 unique strange primes which sum to a prime, each triple numbers are < 1,000.
</pre>
 
=={{header|Ring}}==