Summarize primes: Difference between revisions

m
→‎{{header|REXX}}: changed comments and whitespace.
m (→‎{{header|Raku}}: trivial modification to make it do double duty)
m (→‎{{header|REXX}}: changed comments and whitespace.)
Line 1,004:
=={{header|REXX}}==
<lang rexx>/*REXX pgm finds summation primes P, primes which the sum of primes up to P are prime. */
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/
call genP /*build array of semaphores for primes.*/
w= 30; w2= w*2%3; pad= left('',w-w2) /*the width of the columns two & three.*/
@sumPtitle= ' summation primes which the sum of primes up to P is also prime, P < ' ,
commas(hi)
say ' index │' center(subword(@sumptitle, 1, 2), w) center('prime sum', w) /*display title.*/
say '───────┼'center("" , 1 + (w+1)*2, '─') /* " sep. */
sPrimesfound= 0 /*initialize # of summation primes. */
pSum= 0 $= 0 /*sum of primes up to the current prime*/
do j=1 for hi-1; p= @.j; pSum$= pSum$ + p /*find summation primes within range. */
if \!.pSum$ then iterate /*Is sum─of─primes a prime? Then skip.*/
sPrimes found= sPrimesfound + 1 /*bump the number of nice summation primes. */
say right(j, 6) '│'strip( right(commas(p), w2)pad || right(commas(pSum$), w2), "T")
end /*j*/
 
say '───────┴'center("" , 1 + (w+1)*2, '─') /*display foot separator after output. */
say
say 'Found ' commas(sPrimesfound) @sumPtitle
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/