Substring primes: Difference between revisions

Content added Content deleted
(Added Sidef)
m (→‎{{header|REXX}}: changed some comments, simplified the code.)
Line 464: Line 464:
say ' index │'center(title, 1 + cols*(w+1) ) /*display the title of the output. */
say ' index │'center(title, 1 + cols*(w+1) ) /*display the title of the output. */
say '───────┼'center("" , 1 + cols*(w+1), '─') /* " " separator " " " */
say '───────┼'center("" , 1 + cols*(w+1), '─') /* " " separator " " " */
found= 0; idx= 1 /*initialize # of nice primes and index*/
found= 0; idx= 1 /*define # substring primes found; IDX.*/
$= /*a list of substring primes (so far). */
$= /*a list of substring primes (so far). */
do j=1 for #; x= @.j; x2= substr(x, 2) /*search for primes that fit criteria. */
do j=1 for #; x= @.j; x2= substr(x, 2) /*search for primes that fit criteria. */
Line 476: Line 476:
end /*k*/
end /*k*/


found= found + 1 /*bump the number of nice primes. */
found= found + 1 /*bump the number of substring primes. */
if cols<0 then iterate /*Build the list (to be shown later)? */
$= $ right( commas(j), w) /*add a substring prime ──► $ list. */
c= commas(j) /*maybe add commas to the number. */
$= $ right(c, max(w, length(c) ) ) /*add a nice prime ──► list, allow big#*/
if found//cols\==0 then iterate /*have we populated a line of output? */
if found//cols\==0 then iterate /*have we populated a line of output? */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
Line 501: Line 499:
if j// 3==0 then iterate /*" " " 3? */
if j// 3==0 then iterate /*" " " 3? */
if j// 7==0 then iterate /*" " " 7? */
if j// 7==0 then iterate /*" " " 7? */
/* [↑] the above 3 lines saves time.*/
do k=5 while s.k<=j /* [↓] divide by the known odd primes.*/
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. ___ */
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */