Tau number: Difference between revisions
Undo revision 365760 by Walterpachl (talk)
Walterpachl (talk | contribs) (→{{header|REXX}}: overhauled) |
Walterpachl (talk | contribs) (Undo revision 365760 by Walterpachl (talk)) Tag: Undo |
||
Line 2,848:
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX pgm displays N tau numbers, an integer divisible by the # of its divisors). */
@tau= ' the first ' commas(n) " tau numbers " /*the title of the tau numbers table. */
/* for a range of numbers */▼
say ' index │'center(@tau, 1 + cols*(w+1) ) /*display the title of the output table*/
▲Parse Arg lo hi cols . /*obtain optional argument from the CL.*/
say '───────┼'center("" , 1 + cols*(w+1), '─') /* " " header " " " " */
▲If lo=='' | lo==',' Then lo=1 /*Not specified? Then use the default.*/
▲If hi=='' | hi==',' Then hi=lo+100-1 /*Not specified? Then use the default.*/
#= # + 1 /*bump the count of tau numbers found. */
if #//cols\==0 then iterate /*Not a multiple of cols? Don't show. */
say center(idx, 7)'│' substr($, 2) /*display partial list to the terminal.*/
idx= idx + cols; $= /*bump idx by number of cols; nullify $*/
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
say '───────┴'center("" , 1 + cols*(w+1), '─')
▲ line=line right(tau(j),w) /* add a tau number to the output line. */
exit 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
/*──────────────────────────────────────────────────────────────────────────────────────*/
tau: procedure; parse arg x 1 y /*X and $ are both set from the arg.*/
if x<6 then return 2 + (x==4) - (x==1) /*some low #s should be handled special*/
▲ End /*j*/
do j=3 for x%2-3 by 1+odd while j<y /*for odd number, skip even numbers. */
#= # + 2; y= x % j /*bump # of divisors; calculate limit.*/
end /*j*/ /* [↑] this form of DO loop is faster.*/
▲ If odd & j//2=0 Then /* even j can't be a divisor of an odd x*/
▲ If x//j==0 Then /* if no remainder, then found a divisor*/
▲ tau=tau+2 /* bump n of divisors */
▲ If j*j=x Then /* x is a square */
▲ tau=tau+1 /* its root is a divisor */
▲ Return tau</syntaxhighlight>
{{out|output|text= when using the default input:}}
<pre>
index │ the first 100 tau numbers
───────┼───────────────────────────────────────────────────────────────────────────────────────────
1 │ 1 2 8 9 12 18 24 36 40 56
11
21 │
61 │ 600 612 625 632 636 640 664 672 684 708
71 │ 712 720 732 776 792 804 808 824 828 852
81 │ 856 864 872 876 880 882 896 904 936 948
91 │ 972 996 1,016 1,040 1,044 1,048 1,056 1,068 1,089 1,096
───────┴───────────────────────────────────────────────────────────────────────────────────────────
</pre>
|