Anonymous user
Numbers whose binary and ternary digit sums are prime: Difference between revisions
Numbers whose binary and ternary digit sums are prime (view source)
Revision as of 13:40, 8 June 2021
, 2 years ago→{{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. */
if cols>0 then say ' index │'center(
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─') /*maybe show sep. */
$= /*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 " " */
if cols<1 then iterate /*Only showing the summary? Then skip.*/
$= $ right( commas(j), w) /*add a commatized integer ───► $ list.*/
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,013:
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
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 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:
/*──────────────────────────────────────────────────────────────────────────────────────*/
tBase: procedure; parse arg x,toBase;
do while x>=toBase; y= substr($, x//toBase+1, 1)y; x= x % toBase
end /*while*/
|