Tau number: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) →{{header|REXX}}: overhauled |
Walterpachl (talk | contribs) Undo revision 365760 by Walterpachl (talk) Tag: Undo |
||
Line 2,848: | Line 2,848: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<syntaxhighlight lang="rexx">/*REXX pgm displays N tau numbers, an integer divisible by the # of its divisors). */ |
|||
simplified, |
|||
⚫ | |||
made ooRexx compatible, |
|||
⚫ | |||
corrected for tau of squares, |
|||
⚫ | |||
corrected for a range with fewer than cols numbers. |
|||
w= max(8, length(n) ) /*W: used to align 1st output column. */ |
|||
@tau= ' the first ' commas(n) " tau numbers " /*the title of the tau numbers table. */ |
|||
⚫ | |||
say ' index │'center(@tau, 1 + cols*(w+1) ) /*display the title of the output table*/ |
|||
⚫ | |||
say '───────┼'center("" , 1 + cols*(w+1), '─') /* " " header " " " " */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
do j=1 until #==n /*search for N tau numbers */ |
|||
if j//tau(j) \==0 then iterate /*Is this a tau number? No, then skip.*/ |
|||
#= # + 1 /*bump the count of tau numbers found. */ |
|||
Say 'The number of divisors (tau) from' lo 'to' hi '(inclusive):' |
|||
⚫ | |||
Say '' |
|||
if #//cols\==0 then iterate /*Not a multiple of cols? Don't show. */ |
|||
Say '-number' center(' tau (number of divisors) ',cols*(w+1)+1,'-') |
|||
say center(idx, 7)'│' substr($, 2) /*display partial list to the terminal.*/ |
|||
line='' |
|||
idx= idx + cols; $= /*bump idx by number of cols; nullify $*/ |
|||
c=0 |
|||
⚫ | |||
index=lo |
|||
Do j=lo To hi |
|||
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
|||
c=c+1 |
|||
say '───────┴'center("" , 1 + cols*(w+1), '─') |
|||
⚫ | |||
exit 0 /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
Say center(index,7) line |
|||
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ? |
|||
line='' |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
cnt=0 |
|||
tau: procedure; parse arg x 1 y /*X and $ are both set from the arg.*/ |
|||
Index=index+cols |
|||
if x<6 then return 2 + (x==4) - (x==1) /*some low #s should be handled special*/ |
|||
End |
|||
⚫ | |||
⚫ | |||
⚫ | |||
If line\=='' Then |
|||
else do; #= 4; y= x % 2; end /*Even? " " " " 4. */ |
|||
/* [↑] start with known number of divs*/ |
|||
do j=3 for x%2-3 by 1+odd while j<y /*for odd number, skip even numbers. */ |
|||
/*---------------------------------------------------------------------------------*/ |
|||
⚫ | |||
tau: Procedure |
|||
#= # + 2; y= x % j /*bump # of divisors; calculate limit.*/ |
|||
Parse Arg x |
|||
if j>=y then do; #= # - 1; leave; end /*reached limit?*/ |
|||
⚫ | |||
Return 2+(x==4)-(x==1) |
|||
⚫ | |||
tau=0 |
|||
end /*j*/ /* [↑] this form of DO loop is faster.*/ |
|||
odd=x//2 |
|||
⚫ | |||
Do j=1 by 1 While j*j<x |
|||
⚫ | |||
Iterate |
|||
⚫ | |||
⚫ | |||
End |
|||
⚫ | |||
⚫ | |||
⚫ | |||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |
||
index │ the first 100 tau numbers |
|||
The number of divisors (tau) from 1 to 100 (inclusive): |
|||
───────┼─────────────────────────────────────────────────────────────────────────────────────────── |
|||
1 │ 1 2 8 9 12 18 24 36 40 56 |
|||
-number ----------------- tau (number of divisors) ------------------ |
|||
11 │ 60 72 80 84 88 96 104 108 128 132 |
|||
21 |
21 │ 136 152 156 180 184 204 225 228 232 240 |
||
31 │ 248 252 276 288 296 328 344 348 360 372 |
|||
41 │ 376 384 396 424 441 444 448 450 468 472 |
|||
51 │ 480 488 492 504 516 536 560 564 568 584 |
|||
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> |
</pre> |
||