Sum of the digits of n is substring of n: Difference between revisions

Content deleted Content added
m moved REXX to proper place in alphabetic list of languages.
→‎{{header|REXX}}: added the computer programming language REXX.
Line 6: Line 6:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX pgm finds integers whose sum of decimal digits is a substring of N, N < 1000. */
<lang REXX></lang>
parse arg hi cols . /*obtain optional argument from the CL.*/
output
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 10 /*width of a number in any column. */
@sdsN= ' integers whose sum of decimal digis of N is a substring of N, where N < ' ,
commas(hi)
if cols>0 then say ' index │'center(@sdsN, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
finds= 0; idx= 1 /*initialize # of found numbers & index*/
$= /*a list of found integers (so far). */
do j=0 for hi; #= sumDigs(j) /*obtain sum of the decimal digits of J*/
if pos(#, j)==0 then iterate /*Sum of dec. digs in J? No, then skip*/
finds= finds + 1 /*bump the number of found integers. */
if cols==0 then iterate /*Build the list (to be shown later)? */
$= $ right( commas( commas(j) ), w) /*add a found number ──► the $ list. */
if finds//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*/

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(finds) @sdsN
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 ?
sumDigs:procedure; parse arg x 1 s 2;do j=2 for length(x)-1;s=s+substr(x,j,1);end;return s</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
index │ integers whose sum of decimal digis of N is a substring of N, where N < 1,000
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 0 1 2 3 4 5 6 7 8 9
11 │ 10 20 30 40 50 60 70 80 90 100
21 │ 109 119 129 139 149 159 169 179 189 199
31 │ 200 300 400 500 600 700 800 900 910 911
41 │ 912 913 914 915 916 917 918 919
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────


Found 48 integers whose sum of decimal digis of N is a substring of N, where N < 1,000
</pre>
</pre>



=={{header|Ring}}==
=={{header|Ring}}==