Numbers divisible by their individual digits, but not by the product of their digits.: Difference between revisions

m
→‎{{header|REXX}}: added comments.
m (added a comma.)
m (→‎{{header|REXX}}: added comments.)
Line 1,215:
 
=={{header|REXX}}==
<lang rexx>/*REXX pgm finds numbersintegers divisible by its individual digits, but not by product of digs.*/
parse arg hi cols . /*obtain optional argument from the CL.*/
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. */
@ndnptitle= ' base ten integers < ' commas(hi) " that are divisible" ,
'by its digits, but not by the product of its digits'
if cols>0 then say ' index │'center(@ndnptitle, 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 integers found (so far). */
do j=1 for hi-1; L= length(j); != 1 /*search for integers within the range.*/
if pos(0, j)>0 then iterate /*Does J have a zero? Yes, then skip. */ /* ◄■■■■■■■■ a filter. */
do k=1 for L; x= substr(j, k, 1) /*extract a single decimal digit from J*/
if j//x\==0 then iterate j /*J ÷ by this digit? No, then skip it.*/ /* ◄■■■■■■■■ a filter. */
!= ! * x /*compute the running product of digits*/
end /*k*/
if j//!==0 then iterate /*J ÷ by its digit product? Yes, skip.*/ /* ◄■■■■■■■■ a filter. */
finds= finds + 1 /*bump the number of found integers. */
if cols==<0 then iterate /*Build the list (to be shown later)? */
$= $ right( commas(j), w) /*add the number found to the $ list.*/
if finds//cols\==0 then iterate /*have we populated a line of output? */
Line 1,244:
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' commas(finds) @ndnptitle
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/