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; idx= 1 idx= 1 /*initialize # prime triplets & index.*/
$=; __= ' ' /*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 then iterate /*Build the list (to be shown later)? */
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 tofor max(0, hip %2-@.#%2-1) /*find odd primes from here on. */
parse var j '' -1 _; if _==5 then iterate /*J ÷ by 5? (right digit).*/
if j//3==0 then iterate; if j// 37==0 then iterate /*" ÷" " 3? Is J ÷ by 7? */
if j// 7==0 then iterate /*" ÷ " 7? */
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. ___ */