Anonymous user
Primes whose sum of digits is 25: Difference between revisions
m
→{{header|REXX}}: used faster versions of SUMDIGS and GENP.
(→{{header|REXX}}: added the computer programming language REXX.) |
m (→{{header|REXX}}: used faster versions of SUMDIGS and GENP.) |
||
Line 286:
if cols>0 then say ' index │'center(@primes commas(target), 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
primesT= 0; idx= 1 /*
$= /*
do j=
if sumDigs(
primesT= primesT + 1 /*bump the number of target primes. */
if cols
c= commas(
$= $ right(c, max(w, length(c) ) ) /*add a prime ──► list, allow big #'s.*/
if primesT//cols
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
idx= idx + cols /*bump the index count for the output*/
Line 305:
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
sumDigs:procedure; arg x 1 s 2; do j=2 for length(x)-1; s= s+substr(x,j,1); end; return s▼
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: !.= 0 /*placeholders for primes'
@.1=2;
!.2=1;
#=
/* [↓] generate more primes ≤ high.*/
do j=@.#+2 by 2 to hi /*find odd primes from here on. */
parse var j '' -1 _; if _==5 then iterate /*J divisible by 5?
if j// 3==0 then iterate /*" " " 3?
if j// 7==0 then iterate /*" " " 7?
if j//11==0 then iterate /*" " " 11?
do k=
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
/*──────────────────────────────────────────────────────────────────────────────────────*/
sumDigs: parse arg x 1 s 2 '' -1 z; L= length(x); if L==1 then return s; s= s + z
▲
{{out|output|text= when using the default inputs:}}
<pre>
|