Special divisors: Difference between revisions

m
→‎{{header|REXX}}: used better variable names, changed/add whitespace and comments.
m (added whitespace and highlihting.)
m (→‎{{header|REXX}}: used better variable names, changed/add whitespace and comments.)
Line 342:
 
=={{header|REXX}}==
<lang rexx>/*REXX program finds special divisors: numbers N such that reverse(D) divides ··· */
/*───────────────────────────────────────────── reverse(N) for all divisors D of N. */
parse arg hi cols . /*obtain optional argument from the CL.*/
Line 348:
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 10 /*width of a number in any column. */
@sdnstitle= ' special divisors N that reverse(D) divides reverse(N)' ,
'for all divisors D of N, where N < ' commas(hi)
if cols>0 then say ' index │'center(@sdnstitle, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
sdnsfound= 0; idx= 1 /*initialize # of nicefound primesnumsers and index.*/
$= /*a list of numbers nice primesfound (so far). */
do j=1 for hi-1; r= reverse(j) /*search for special divisors. */
do k=2 to j%2 /*skip the first divisor (unity) & last*/
Line 359:
else iterate j /*Not OK? Skip*/
end /*m*/
sdnsfound= sdnsfound + 1 /*bump the number of special sdns numbersdivisors. */
if cols==<0 then iterate /*Build the list (to be shown later)? */
c= commas(j) /*maybe add commas to the number. */
$= $ right(c, max(w, length(c) ) ) /*add a nicespecial primediv ──►─► list, allow big#*/
if sdnsfound//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*/
Line 371:
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' commas(sdnsfound) @sdnstitle
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/