Anonymous user
Numbers with prime digits whose sum is 13: Difference between revisions
Numbers with prime digits whose sum is 13 (view source)
Revision as of 00:29, 6 July 2021
, 2 years ago→{{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
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 ' 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
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*/
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= when using the internal default inputs:}}
<pre>
index │ decimal numbers found whose digits are prime and sum to 13
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
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
</pre>
|