Anonymous user
Additive primes: Difference between revisions
→{{header|REXX}}: added/changed whitespace and comments, optimized the program.
m (→{{header|REXX}}: changed the GENP subroutine.) |
(→{{header|REXX}}: added/changed whitespace and comments, optimized the program.) |
||
Line 870:
call genP n /*generate all primes under N. */
w= 10 /*width of a number in any column. */
title= " additive primes that are < " commas(n)
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
$= /*a list of additive primes (so far). */
do j=
_= sumDigs(
if cols<0 then iterate /*Build the list (to be shown later)? */
c= commas(
$= $ right(c, max(w, length(c) ) )
if
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
idx= idx + cols /*bump the index count for the output*/
Line 889:
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'found ' commas(
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 895:
sumDigs: parse arg x 1 s 2; do k=2 for length(x)-1; s= s + substr(x,k,1); end; return s
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: parse arg n;
do j=@.#+2 by
parse var j '' -1
if _==5 then iterate; if j// 3==0 then iterate /*J ÷ by 5? J ÷ by 3? */
if j// 7==0 then iterate; if j//11==0 then iterate /*" " " 7? " " " 11? */
/* [↓] divide by the primes. ___ */
do k=6 while
{{out|output|text= when using the default inputs:}}
<pre>
|