Anonymous user
Triplet of three numbers: Difference between revisions
m
→{{header|REXX}}: added filter comments, optimized the GENP subroutine.
m (→{{header|REXX}}: added filter comments, optimized the GENP subroutine.) |
|||
Line 1,559:
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
found= 0;
$=; __= ' ' /*a list of prime triplets (so far). */
do j=1 for hi-1 /*look for prime triplets within range.*/
p1= j - 1; if \!.p1 then iterate /*Is P1 not prime? Then skip it. */ /* ◄■■■■■■■ a filter.*/
p3= j + 3; if \!.p3 then iterate /* " P3 " " " " " */ /* ◄■■■■■■■ a filter.*/
p5= j + 5; if \!.p5 then iterate /* " P5 " " " " " */ /* ◄■■■■■■■ a filter.*/
found= found + 1 /*bump the number of prime triplets. */
if cols<=0
ttt= commas(p1)__ commas(p3)__ commas(p5) /*add commas & blanks to prime triplet.*/
$= $ left( '('ttt")", w) /*add a prime triplet ──► the $ list.*/
Line 1,587:
#=5; sq.#= @.# ** 2 /*number of primes so far; prime². */
/* [↓] generate more primes ≤ high.*/
do j=@.#+2 by 2
parse var j '' -1 _; if
if j//3==0 then
do k=5 while sq.k<=j /* [↓] divide by the known odd primes.*/
if j//@.k==0 then iterate j /*Is J÷@.k ? Then not prime. ___ */
|