Special divisors: Difference between revisions

Content added Content deleted
(Add Cowgol)
m (→‎{{header|REXX}}: simplified the code.)
Line 1,096: Line 1,096:
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 10 /*width of a number in any column. */
w= 10 /*width of a number in any column. */
title= ' special divisors N that reverse(D) divides reverse(N) for all divisiors' ,
title= ' special divisors N that reverse(D) divides reverse(N) for all divisors' ,
' D of N, where N < ' commas(hi)
' D of N, where N < ' hi
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) )
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
found= 0; idx= 1 /*initialize # found numsers and index.*/
found= 0; idx= 1 /*initialize # found numbers and index.*/
$= /*a list of numbers found (so far). */
$= /*a list of numbers found (so far). */
do j=1 for hi-1; r= reverse(j) /*search for special divisors. */
do j=1 for hi-1; r= reverse(j) /*search for special divisors. */
Line 1,108: Line 1,108:
found= found+1 /*bump the number of special divisors. */
found= found+1 /*bump the number of special divisors. */
if cols<0 then iterate /*Build the list (to be shown later)? */
if cols<0 then iterate /*Build the list (to be shown later)? */
c= commas(j) /*maybe add commas to the number. */
$= $ right(j, w) /*add a special divisor ──► the $ list.*/
$= $ right(c, max(w, length(c) ) ) /*add a special div ─► list, allow big#*/
if found//cols\==0 then iterate /*have we populated a line of output? */
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). */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
Line 1,116: Line 1,115:


if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say
say 'Found ' commas(found) title
say 'Found ' found title</lang>
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 default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
index │ special divisors N that reverse(D) divides reverse(N) for all divisiors D of N, where N < 200
index │ special divisors N that reverse(D) divides reverse(N) for all divisors D of N, where N < 200
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 1 2 3 4 5 6 7 8 9 11
1 │ 1 2 3 4 5 6 7 8 9 11
Line 1,136: Line 1,132:
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────


Found 72 special divisors N that reverse(D) divides reverse(N) for all divisiors D of N, where N < 200
Found 72 special divisors N that reverse(D) divides reverse(N) for all divisors D of N, where N < 200
</pre>
</pre>