Numbers whose binary and ternary digit sums are prime: Difference between revisions

m
→‎{{header|REXX}}: simplified the code.
m (→‎{{header|REXX}}: simplified the code.)
Line 996:
call genP /*build array of semaphores for primes.*/
w= 10 /*width of a number in any column. */
@b2b3title= ' positive integers whose binary and ternary digit sums are prime, N < ' commas(n)
if cols>0 then say ' index │'center(@b2b3title, 1 + cols*(w+1) ) /*maybe show title.*/
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─') /*maybe show sep. */
findsfound= 0; idx= 1 /*initialize # of finds and the index. */
$= /*a list of numbers found (so far). */
do j=1 for n-1 /*find #s whose B2 & B3 sums are prime.*/
b2= sumDig( tBase(j, 2) ); if \!.b2 then iterate /*convert to base2, sum digits.*/
b3= sumDig( tBase(j, 3) ); if \!.b3 then iterate /* " " base3 " " */
findsfound= findsfound + 1 /*bump the number of found integers. */
if cols<1 then iterate /*Only showing the summary? Then skip.*/
$= $ right( commas(j), w) /*add a commatized integer ───► $ list.*/
if findsfound//cols\==0 then iterate /*have we populated a line of output? */
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,013:
 
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─') /*show foot sep ? */
say
say 'Found ' commas(findsfound) @b2b3title /*show summary. */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 1,021:
sumDig: procedure; parse arg x 1 s 2;do j=2 for length(x)-1;s=s+substr(x,j,1);end;return s
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: !.=0; @= 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103
#!.= words(@)0; do p=1 for #words(@); _= word(@, p); !._= 1; end; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
tBase: procedure; parse arg x,toBase; y=; y=; $= 0123456789
do while x>=toBase; y= substr($, x//toBase+1, 1)y; x= x % toBase
end /*while*/