Numbers with prime digits whose sum is 13: Difference between revisions

m
→‎{{header|REXX}}: used a better format for showing the output.
m (changed numbers to positive integers, and digits to decimal digits (for the sum).)
m (→‎{{header|REXX}}: used a better format for showing the output.)
Line 1,681:
=={{header|REXX}}==
<lang rexx>/*REXX pgm finds and displays all decimal numbers whose digits are prime and sum to 13. */
parse arg LO= 337;HI COLS . HI= 322222; #= 0 /*define low&highobtain rangeoptional forarguments #s;from #the countCL*/
if LO=='' | LO=="," then LO= 337 /*Not specified? Then use the default.*/
if HI=='' | HI=="," then HI= 322222 /* " " " " " " */
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 10 /*width of a number in any column. */
say # title= ' decimal numbers found whose digits are prime and the decimal digits sum to 13 '</lang>
say ' index │'center(title, 1 + cols*(w+1) )
say '───────┼'center("" , 1 + cols*(w+1), '─')
w= 10 /*max width of a integer in any column.*/
found= 0; idx= 1 /*the number of numbers found (so far).*/
$= /*variable to hold the list of #s found*/
do j=LO for HI-LO+1 /*search for numbers in this range. */
Line 1,690 ⟶ 1,699:
sum= sum + substr(j, k, 1) /*sum some middle decimal digits of J.*/
end /*k*/
if sum\==13 then iterate then iterate /*Sum not equal to 13? Then skip this #*/
#found= #found + 1; $= $ j /*bump #the count;number appendof #numbers found. to the $ list.*/
c= commas(j) /*maybe add commas to the number. */
$= $ right( commas(j), w) /*add the found number ───► the $ list.*/
if found//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*/
end /*j*/
 
sayif strip($); \=='' then say center(idx, 7)"│" substr($, 2) /*possible display theresidual output list to the term. */
say '───────┴'center("" , 1 + cols*(w+1), '─')
say # ' decimal numbers found whose digits are prime and the decimal digits sum to 13'</lang>
say
say 'Found ' commas(found) title
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 _</lang>
{{out|output|text=&nbsp; when using the internal default inputs:}}
<pre>
index │ decimal numbers found whose digits are prime and sum to 13
337 355 373 535 553 733 2227 2272 2335 2353 2533 2722 3235 3253 3325 3352 3523 3532 5233 5323 5332 7222 22225 22252 22333 22522 23233 23323 23332 25222 32233 32323 32332 33223 33232 33322 52222 222223 222232 222322 223222 232222 322222
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 337 355 373 535 553 733 2,227 2,272 2,335 2,353
11 │ 2,533 2,722 3,235 3,253 3,325 3,352 3,523 3,532 5,233 5,323
21 │ 5,332 7,222 22,225 22,252 22,333 22,522 23,233 23,323 23,332 25,222
31 │ 32,233 32,323 32,332 33,223 33,232 33,322 52,222 222,223 222,232 222,322
41 │ 223,222 232,222 322,222
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
 
Found 43 decimal numbers found whose digits are prime and the decimal digits sum to 13
</pre>