Anonymous user
Nice primes: Difference between revisions
m
→{{header|REXX}}: simplified the code.
(→{{header|PL/M}}: Bug fix) |
m (→{{header|REXX}}: simplified the code.) |
||
Line 1,095:
call genP /*build array of semaphores for primes.*/
w= 10 /*width of a number in any column. */
if cols>0 then say ' index │'center(
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
$= /*a list of nice primes (so far). */
do j=lo+1 to hi-1; if \!.j then iterate /*search for nice primes within range*/
digRoot= 1 + (j - 1) // 9 /*obtain the digital root of J. */
if \!.digRoot then iterate /*Is digRoot prime? No, then skip it.*/
if cols
c= commas(j) /*maybe add commas to the number. */
$= $ right(c, max(w, length(c) ) ) /*add a nice prime ──► list, allow big#*/
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 1,115:
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. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP:
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? (right dig)*/
if j// 3==0 then iterate /*" " " 3? */
if j// 7==0 then iterate /*" " " 7? */
/* [↑] the above
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. ___ */
|