Tau number: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) (Undo revision 365760 by Walterpachl (talk)) Tag: Undo |
Walterpachl (talk | contribs) (→{{header|REXX}}: overhauled) |
||
Line 2,848: | Line 2,848: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Simplified, use the tau function of the respective task, ooRexx compatible |
|||
<syntaxhighlight lang="rexx">/*REXX pgm displays |
<syntaxhighlight lang="rexx">/*REXX pgm displays N tau numbers (integers divisible by the # of its divisors). */ |
||
parse arg n cols . /*obtain optional argument from the CL.*/ |
|||
Parse Arg n cols . /*obtain optional argument from the CL. */ |
|||
If n=='' | n==',' Then n= 100 /*Not specified? Then use the default. */ |
|||
If cols=='' | cols==',' Then cols= 10 /*Not specified? Then use the default. */ |
|||
w= max(8, length(n) ) /*W: used to align 1st output column. */ |
|||
w=6 /*W: used To align 1st output column. */ |
|||
ttau=' the first ' commas(n) ' tau numbers' /* the title of the table. */ |
|||
Say ' index ¦'center(ttau,cols*(w+1) ) /* display the title */ |
|||
⚫ | |||
⚫ | |||
idx=1 |
|||
⚫ | |||
nn=0 /* number of tau numbers */ |
|||
dd='' |
|||
⚫ | |||
Do j=1 Until nn==n /* search for N tau numbers */ |
|||
If j//tau(j)==0 Then Do /* If this is a tau number */ |
|||
nn=nn+1 /* bump the count of tau numbers found. */ |
|||
dd=dd right(commas(j),w) /* add a tau number To the output list. */ |
|||
If nn//cols==0 Then Do /* a line is full */ |
|||
⚫ | |||
idx= idx+cols /* bump idx by number of cols */ |
|||
⚫ | |||
dd='' |
|||
⚫ | |||
End |
|||
exit 0 /*stick a fork in it, we're all done. */ |
|||
End |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
End |
|||
⚫ | |||
If dd\=='' Then Say center(idx,7)'¦' substr(dd,2) /*possible display rest */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
Say '--------'center('' ,cols*(w+1),'-') |
|||
tau: procedure; parse arg x 1 y /*X and $ are both set from the arg.*/ |
|||
Exit 0 /*stick a fork in it,we're all done. */ |
|||
/*--------------------------------------------------------------------------------*/ |
|||
⚫ | |||
⚫ | |||
if odd then do; #= 2; end /*Odd? Assume divisor count of 2. */ |
|||
/*--------------------------------------------------------------------------------*/ |
|||
else do; #= 4; y= x % 2; end /*Even? " " " " 4. */ |
|||
tau: Procedure |
|||
/* [↑] start with known number of divs*/ |
|||
Parse Arg x |
|||
do j=3 for x%2-3 by 1+odd while j<y /*for odd number, skip even numbers. */ |
|||
If x<6 Then /* some low numbers are handled special */ |
|||
Return 2+(x==4)-(x==1) |
|||
#= # + 2; y= x % j /*bump # of divisors; calculate limit.*/ |
|||
tau=0 |
|||
if j>=y then do; #= # - 1; leave; end /*reached limit?*/ |
|||
odd=x//2 |
|||
end /* ___ */ |
|||
Do j=1 by 1 While j*j<x |
|||
else if j*j>x then leave /*only divide up to √ x */ |
|||
If odd & j//2=0 Then /* even j can't be a divisor of an odd x*/ |
|||
Iterate |
|||
⚫ | |||
If x//j==0 Then /* If no remainder,Then found a divisor*/ |
|||
⚫ | |||
End |
|||
⚫ | |||
⚫ | |||
⚫ | |||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |
||
index |
index ¦ the first 100 tau numbers |
||
-------+---------------------------------------------------------------------- |
|||
───────┼─────────────────────────────────────────────────────────────────────────────────────────── |
|||
1 |
1 ¦ 1 2 8 9 12 18 24 36 40 56 |
||
11 |
11 ¦ 60 72 80 84 88 96 104 108 128 132 |
||
21 |
21 ¦ 136 152 156 180 184 204 225 228 232 240 |
||
31 |
31 ¦ 248 252 276 288 296 328 344 348 360 372 |
||
41 |
41 ¦ 376 384 396 424 441 444 448 450 468 472 |
||
51 |
51 ¦ 480 488 492 504 516 536 560 564 568 584 |
||
61 |
61 ¦ 600 612 625 632 636 640 664 672 684 708 |
||
71 |
71 ¦ 712 720 732 776 792 804 808 824 828 852 |
||
81 |
81 ¦ 856 864 872 876 880 882 896 904 936 948 |
||
91 |
91 ¦ 972 996 1,016 1,040 1,044 1,048 1,056 1,068 1,089 1,096 |
||
------------------------------------------------------------------------------</pre> |
|||
───────┴─────────────────────────────────────────────────────────────────────────────────────────── |
|||
</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |