Tau number: Difference between revisions

32,151 bytes added ,  1 month ago
Added Prolog
(→‎J: insert {{needs-review}} as a consequence of task qualification in previous revision)
(Added Prolog)
 
(45 intermediate revisions by 20 users not shown)
Line 17:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F tau(n)
V ans = 0
V i = 1
Line 41:
ans.append(n)
n++
print(ans)</langsyntaxhighlight>
 
{{out}}
<pre>
[1, 2, 8, 9, 12, 18, 24, 36, 40, 56, 60, 72, 80, 84, 88, 96, 104, 108, 128, 132, 136, 152, 156, 180, 184, 204, 225, 228, 232, 240, 248, 252, 276, 288, 296, 328, 344, 348, 360, 372, 376, 384, 396, 424, 441, 444, 448, 450, 468, 472, 480, 488, 492, 504, 516, 536, 560, 564, 568, 584, 600, 612, 625, 632, 636, 640, 664, 672, 684, 708, 712, 720, 732, 776, 792, 804, 808, 824, 828, 852, 856, 864, 872, 876, 880, 882, 896, 904, 936, 948, 972, 996, 1016, 1040, 1044, 1048, 1056, 1068, 1089, 1096]
</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">CARD FUNC DivisorCount(CARD n)
CARD result,p,count
result=1
WHILE (n&1)=0
DO
result==+1
n=n RSH 1
OD
 
p=3
WHILE p*p<=n
DO
count=1
WHILE n MOD p=0
DO
count==+1
n==/p
OD
result==*count
p==+2
OD
 
IF n>1 THEN
result==*2
FI
RETURN (result)
 
PROC Main()
CARD n=[1],max=[100],count=[0],divCount
 
WHILE count<max
DO
divCount=DivisorCount(n)
IF n MOD divCount=0 THEN
PrintC(n) Put(32)
count==+1
FI
n==+1
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Tau_number.png Screenshot from Atari 8-bit computer]
<pre>
1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96 104 108 128 132 136 152 156 180 184
204 225 228 232 240 248 252 276 288 296 328 344 348 360 372 376 384 396 424 441
444 448 450 468 472 480 488 492 504 516 536 560 564 568 584 600 612 625 632 636
640 664 672 684 708 712 720 732 776 792 804 808 824 828 852 856 864 872 876 880
882 896 904 936 948 972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
 
=={{header|ALGOL 68}}==
{{Trans|C++}}
<langsyntaxhighlight lang="algol68">BEGIN # find tau numbers - numbers divisible by the count of theoir divisors #
# calculates the number of divisors of v #
PROC divisor count = ( INT v )INT:
Line 88 ⟶ 140:
OD
END
END</langsyntaxhighlight>
{{out}}
<pre>
Line 105 ⟶ 157:
 
=={{header|ALGOL-M}}==
<langsyntaxhighlight lang="algolm">begin
 
integer array dcount[1:1100];
Line 139 ⟶ 191:
i := i + 1;
end;
end</langsyntaxhighlight>
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 155 ⟶ 207:
{{works with|Dyalog APL}}
 
<langsyntaxhighlight APLlang="apl">(⊢(/⍨)(0=(0+.=⍳|⊢)|⊢)¨)⍳ 1096</langsyntaxhighlight>
 
{{out}}
Line 167 ⟶ 219:
 
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">on factorCount(n)
if (n < 1) then return 0
set counter to 2
Line 196 ⟶ 248:
set output to output as text
set AppleScript's text item delimiters to astid
return output</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">"First 100 tau numbers:
1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240 248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472 480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708 712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948 972 996 1016 1040 1044 1048 1056 1068 1089 1096"</langsyntaxhighlight>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">tau: function [x] -> size factors x
 
found: 0
Line 219 ⟶ 271:
]
i: i + 1
]</langsyntaxhighlight>
 
{{out}}
Line 233 ⟶ 285:
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Asymptote}}==
<syntaxhighlight lang="Asymptote">int n = 0;
int num = 0;
int limit = 100;
write("The first $limit tau numbers are:");
do {
++n;
int tau = 0;
for (int m = 1; m <= n; ++m) {
if (n % m == 0) ++tau;
}
if (n % tau == 0) {
++num;
write(format("%5d", n), suffix=none);
}
} while (num < limit);</syntaxhighlight>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">n := c:= 0
while (c<100)
if isTau(++n)
c++, result .= SubStr(" " n, -3) . (Mod(c, 10) ? " " : "`n")
MsgBox % result
return
 
isTau(num){
return (num/(n := StrSplit(Factors(num), ",").Count()) = floor(num/n))
}
 
Factors(n) {
Loop, % floor(sqrt(n))
v := A_Index = 1 ? 1 "," n : mod(n,A_Index) ? v : v "," A_Index "," n//A_Index
Sort, v, N U D,
Return, v
}</syntaxhighlight>
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f TAU_NUMBER.AWK
BEGIN {
Line 258 ⟶ 357:
return(count)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 275 ⟶ 374:
 
=={{header|BASIC}}==
<syntaxhighlight lang="basic">10 DEFINT A-Z
 
<lang BASIC>10 DEFINT A-Z
20 S=0: N=1
30 C=1
Line 283 ⟶ 381:
60 N=N+1
70 IF S<100 THEN 30
80 END</langsyntaxhighlight>
 
{{out}}
 
<pre> 1 2 8 9 12
18 24 36 40 56
Line 307 ⟶ 403:
972 996 1016 1040 1044
1048 1056 1068 1089 1096</pre>
 
==={{header|Applesoft BASIC}}===
{{trans|MSX Basic}}
<syntaxhighlight lang="vbnet">100 HOME
110 PRINT "The first 100 tau numbers are:"
120 N = 0
130 NUM = 0
140 LIMIT = 100
150 IF NUM >= LIMIT THEN GOTO 230
160 N = N+1
170 TAU = 0
180 FOR M = 1 TO N
190 IF N - INT(N/M) * M = 0 THEN TAU = TAU+1
200 NEXT M
210 IF N - INT(N/TAU) * TAU = 0 THEN NUM = NUM+1 : PRINT N; " ";
220 GOTO 150
230 END</syntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">print "The first 100 tau numbers are:"
 
n = 0
num = 0
limit = 100
while num < limit
n += 1
tau = 0
for m = 1 to n
if n mod m = 0 then tau += 1
next m
if n mod tau = 0 then
num += 1
if num mod 10 = 1 then print
print rjust(string(n), 6);
end if
end while
end</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{trans|BASIC256}}
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">100 cls
110 print "The first 100 tau numbers are:"
120 n = 0
130 num = 0
140 limit = 100
150 while num < limit
160 n = n+1
170 tau = 0
180 for m = 1 to n
190 if n mod m = 0 then tau = tau+1
200 next m
210 if n mod tau = 0 then
220 num = num+1
230 if num mod 10 = 1 then print
240 print n,
250 endif
260 wend
270 print
280 end</syntaxhighlight>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
Dim c As Integer = 0, i As Integer = 1
Print "The first 100 tau numbers are:\n"
While c < 100
If isTau(i) Then
Print Format$(i, "######");
c += 1
If c Mod 10 = 0 Then Print
End If
i += 1
Wend
 
End
 
Function numdiv(n As Integer) As Integer
 
Dim c As Integer = 2
For i As Integer = 2 To (n + 1) \ 2
If n Mod i = 0 Then c += 1
Next
Return c
 
End Function
 
Function isTau(n As Integer) As Boolean
 
If n = 1 Then Return True
Return IIf(n Mod numdiv(n) = 0, True, False)
 
End Function</syntaxhighlight>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{trans|Chipmunk Basic}}
<syntaxhighlight lang="qbasic">100 CLS
110 PRINT "The first 100 tau numbers are:"
120 N = 0
130 NUM = 0
140 LIMIT = 100
150 WHILE NUM < LIMIT
160 N = N+1
170 TAU = 0
180 FOR M = 1 TO N
190 IF N MOD M = 0 THEN TAU = TAU+1
200 NEXT M
210 IF N MOD TAU = 0 THEN NUM = NUM+1 : PRINT N; " ";
220 WEND
230 END</syntaxhighlight>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "TauNr.bas"
110 LET LIMIT=100
120 LET N,NUM=0
130 PRINT "The first";LIMIT;"tau numbers are:"
140 DO WHILE NUM<LIMIT
150 LET N=N+1
160 LET TAU=0
170 FOR M=1 TO N
180 IF MOD(N,M)=0 THEN LET TAU=TAU+1
190 NEXT
200 IF MOD(N,TAU)=0 THEN LET NUM=NUM+1:PRINT N,
210 LOOP</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
<syntaxhighlight lang="qbasic">10 PRINT "THE FIRST 100 TAU NUMBERS ARE:"
20 LET N = 0
30 LET M = 0
40 LET L = 100
50 IF M >= L THEN 190
60 LET N = N + 1
70 LET T = 0
80 FOR I = 1 TO N
90 IF N - INT(N/I) * I = 0 THEN 110
100 GOTO 120
110 LET T = T + 1
120 NEXT I
130 IF N - INT(N/T) * T = 0 THEN 160
140 GOTO 50
150 STOP
160 LET M = M + 1
170 PRINT N;
180 GOTO 140
190 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
{{trans|Chipmunk Basic}}
<syntaxhighlight lang="qbasic">100 CLS
110 PRINT "The first 100 tau numbers are:"
120 N = 0
130 NUM = 0
140 LIMIT = 100
150 IF NUM > LIMIT THEN GOTO 230
160 N = N+1
170 TAU = 0
180 FOR M = 1 TO N
190 IF N MOD M = 0 THEN TAU = TAU+1
200 NEXT M
210 IF N MOD TAU = 0 THEN NUM = NUM+1 : PRINT N;
220 GOTO 150
230 END</syntaxhighlight>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
<syntaxhighlight lang="qbasic">PRINT "The first 100 tau numbers are:"
 
n = 0
num = 0
limit = 100
DO
n = n + 1
tau = 0
FOR m = 1 TO n
IF n MOD m = 0 THEN tau = tau + 1
NEXT m
IF n MOD tau = 0 THEN
num = num + 1
IF num MOD 10 = 1 THEN PRINT
PRINT USING " ####"; n; '""; n; " ";
END IF
LOOP WHILE num < limit
END</syntaxhighlight>
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
<syntaxhighlight lang="vb">print "The first 100 tau numbers are:"
 
n = 0
num = 0
limit = 100
while num < limit
n = n +1
tau = 0
for m = 1 to n
if n mod m = 0 then tau = tau +1
next m
if n mod tau = 0 then
num = num +1
if num mod 10 = 1 then print
print using("######", n);
end if
wend
end</syntaxhighlight>
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">LET n = 0
LET num = 0
LET limit = 100
DO
LET n = n + 1
LET tau = 0
FOR m = 1 TO n
IF REMAINDER(n, m) = 0 THEN LET tau = tau + 1
NEXT m
IF REMAINDER(n, tau) = 0 THEN
LET num = num + 1
IF REMAINDER(num, 10) = 1 THEN PRINT
PRINT ""; n; " ";
END IF
LOOP WHILE num < limit
END</syntaxhighlight>
 
==={{Header|Tiny BASIC}}===
<syntaxhighlight lang="qbasic">REM Rosetta Code problem: https://rosettacode.org/wiki/Tau_number
REM by Jjuanhdez, 11/2023
 
REM Tau number
 
LET C = 0
LET N = 0
LET X = 100
LET T = 0
10 LET C = C + 1
LET T = 0
LET M = 1
20 IF C - (C / M) * M <> 0 THEN GOTO 30
LET T = T + 1
30 LET M = M + 1
IF M < C + 1 THEN GOTO 20
IF C - (C / T) * T <> 0 THEN GOTO 40
LET N = N + 1
PRINT C
40 IF N < X THEN GOTO 10
END
</syntaxhighlight>
 
==={{header|XBasic}}===
{{trans|BASIC256}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Tau number"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
PRINT "The first 100 tau numbers are:"
 
n = 0
num = 0
limit = 100
DO WHILE num < limit
INC n
tau = 0
FOR m = 1 TO n
IF n MOD m = 0 THEN INC tau
NEXT m
IF n MOD tau = 0 THEN
INC num
IF num MOD 10 = 1 THEN PRINT
PRINT FORMAT$("######", n);
END IF
LOOP
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">print "The first 100 tau numbers are:"
 
n = 0
num = 0
limit = 100
while num < limit
n = n + 1
tau = 0
for m = 1 to n
if mod(n, m) = 0 then tau = tau + 1 : fi
next m
if mod(n, tau) = 0 then
num = num + 1
if mod(num, 10) = 1 then print : fi
print n using "####";
end if
wend
print
end</syntaxhighlight>
 
 
=={{header|BCPL}}==
<langsyntaxhighlight BCPLlang="bcpl">get "libhdr"
 
// Count the divisors of 1..N
Line 341 ⟶ 739:
n := n + 1
$)
$)</langsyntaxhighlight>
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 356 ⟶ 754:
=={{header|C}}==
{{trans|C++}}
<langsyntaxhighlight lang="c">#include <stdio.h>
 
unsigned int divisor_count(unsigned int n) {
Line 398 ⟶ 796:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>The first 100 tau numbers are:
Line 413 ⟶ 811:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
 
Line 447 ⟶ 845:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 463 ⟶ 861:
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
 
=={{header|Clojure}}==
{{trans|Raku}}
<syntaxhighlight lang="clojure">(require '[clojure.string :refer [join]])
(require '[clojure.pprint :refer [cl-format]])
 
(defn divisors [n] (filter #(zero? (rem n %)) (range 1 (inc n))))
 
(defn display-results [label per-line width nums]
(doall (map println (cons (str "\n" label ":") (list
(join "\n" (map #(join " " %)
(partition-all per-line (map #(cl-format nil "~v:d" width %) nums)))))))))
 
(display-results "Tau function - first 100" 20 3
(take 100 (map (comp count divisors) (drop 1 (range)))))
 
(display-results "Tau numbers – first 100" 10 5
(take 100 (filter #(zero? (rem % (count (divisors %)))) (drop 1 (range)))))
 
(display-results "Divisor sums – first 100" 20 4
(take 100 (map #(reduce + (divisors %)) (drop 1 (range)))))
 
(display-results "Divisor products – first 100" 5 16
(take 100 (map #(reduce * (divisors %)) (drop 1 (range)))))</syntaxhighlight>
{{Out}}
<pre>
Tau function - first 100:
1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
4 4 2 8 3 4 4 6 2 8 2 6 4 4 4 9 2 4 4 8
2 8 2 6 6 4 2 10 3 6 4 6 2 8 4 8 4 4 2 12
2 4 6 7 4 8 2 6 4 8 2 12 2 4 6 6 4 8 2 10
5 4 2 12 4 4 4 8 2 12 4 6 4 4 4 12 2 6 6 9
 
Tau numbers – first 100:
1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1,016 1,040 1,044 1,048 1,056 1,068 1,089 1,096
 
Divisor sums – first 100:
1 3 4 7 6 12 8 15 13 18 12 28 14 24 24 31 18 39 20 42
32 36 24 60 31 42 40 56 30 72 32 63 48 54 48 91 38 60 56 90
42 96 44 84 78 72 48 124 57 93 72 98 54 120 72 120 80 90 60 168
62 96 104 127 84 144 68 126 96 144 72 195 74 114 124 140 96 168 80 186
121 126 84 224 108 132 120 180 90 234 112 168 128 144 120 252 98 171 156 217
 
Divisor products – first 100:
1 2 3 8 5
36 7 64 27 100
11 1,728 13 196 225
1,024 17 5,832 19 8,000
441 484 23 331,776 125
676 729 21,952 29 810,000
31 32,768 1,089 1,156 1,225
10,077,696 37 1,444 1,521 2,560,000
41 3,111,696 43 85,184 91,125
2,116 47 254,803,968 343 125,000
2,601 140,608 53 8,503,056 3,025
9,834,496 3,249 3,364 59 46,656,000,000
61 3,844 250,047 2,097,152 4,225
18,974,736 67 314,432 4,761 24,010,000
71 139,314,069,504 73 5,476 421,875
438,976 5,929 37,015,056 79 3,276,800,000
59,049 6,724 83 351,298,031,616 7,225
7,396 7,569 59,969,536 89 531,441,000,000
8,281 778,688 8,649 8,836 9,025
782,757,789,696 97 941,192 970,299 1,000,000,000
</pre>
=={{header|CLU}}==
<syntaxhighlight lang="clu">% Count the divisors of [1..N]
count_divisors = proc (n: int) returns (sequence[int])
divs: array[int] := array[int]$fill(1, n, 1)
for i: int in int$from_to(2, n) do
for j: int in int$from_to_by(i, n, i) do
divs[j] := divs[j] + 1
end
end
return(sequence[int]$a2s(divs))
end count_divisors
 
% Find Tau numbers up to a given limit
tau_numbers = iter (lim: int) yields (int)
divs: sequence[int] := count_divisors(lim)
n: int := 0
while n < lim do
n := n + 1
if n // divs[n] = 0 then yield(n) end
end
end tau_numbers
 
% Show the first 100 Tau numbers
start_up = proc ()
po: stream := stream$primary_output()
seen: int := 0
for n: int in tau_numbers(1100) do
seen := seen + 1
stream$putright(po, int$unparse(n), 5)
if seen // 10 = 0 then stream$putl(po, "") end
if seen >= 100 then break end
end
end start_up</syntaxhighlight>
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
# <nowiki>Numbered list item</nowiki>
 
# Get count of positive divisors of number
Line 498 ⟶ 1,016:
nums := nums + 1;
end if;
end loop;</langsyntaxhighlight>
 
{{out}}
Line 513 ⟶ 1,031:
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Craft Basic}}==
<syntaxhighlight lang="basic">define count = 0, num = 0, mod = 0
define nums = 100, tau = 0
 
do
 
let count = count + 1
let tau = 0
let mod = 1
 
do
 
if count % mod = 0 then
 
let tau = tau + 1
 
endif
 
let mod = mod + 1
 
loop mod < count + 1
 
if count % tau = 0 then
 
let num = num + 1
print count
 
endif
 
loop num < nums</syntaxhighlight>
{{out| Output}}<pre>1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96 104 108 128 132 136 152 156 180 184 204 225 228 232 240 248 252 276 288 296 328 344 348 360 372 376 384 396 424 441 444 448 450 468 472 480 488 492 504 516 536 560 564 568 584 600 612 625 632 636 640 664 672 684 708 712 720 732 776 792 804 808 824 828 852 856 864 872 876 880 882 896 904 936 948 972 996 1016 1040 1044 1048 1056 1068 1089 1096 </pre>
 
=={{header|D}}==
{{trans|C++}}
<langsyntaxhighlight lang="d">import std.stdio;
 
uint divisor_count(uint n) {
Line 553 ⟶ 1,101:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>The first 100 tau numbers are:
Line 566 ⟶ 1,114:
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Dart}}==
{{trans|C++}}
<syntaxhighlight lang="dart">int divisorCount(int n) {
int total = 1;
// Deal with powers of 2 first
for (; (n & 1) == 0; n >>= 1) total++;
// Odd prime factors up to the square root
for (int p = 3; p * p <= n; p += 2) {
int count = 1;
for (; n % p == 0; n ~/= p) count++;
total *= count;
}
// If n > 1 then it's prime
if (n > 1) total *= 2;
return total;
}
 
void main() {
const int limit = 100;
print("The first $limit tau numbers are:");
int count = 0;
for (int n = 1; count < limit; n++) {
if (n % divisorCount(n) == 0) {
print(n.toString().padLeft(6));
count++;
}
}
}</syntaxhighlight>
 
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Tau_number;
 
Line 617 ⟶ 1,194:
 
{$IFNDEF UNIX} readln; {$ENDIF}
end.</langsyntaxhighlight>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">/* Generate a table of the amount of divisors for each number */
proc nonrec div_count([*]word divs) void:
word max, i, j;
max := dim(divs,1)-1;
divs[0] := 0;
for i from 1 upto max do divs[i] := 1 od;
for i from 2 upto max do
for j from i by i upto max do
divs[j] := divs[j] + 1
od
od
corp
 
/* Find Tau numbers */
proc nonrec main() void:
[1100]word divs;
word n, seen;
div_count(divs);
seen := 0;
n := 0;
while n := n + 1; seen < 100 do
if n % divs[n] = 0 then
seen := seen + 1;
write(n:5);
if seen % 10 = 0 then writeln() fi
fi
od
corp</syntaxhighlight>
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func cntdiv n .
i = 1
while i <= sqrt n
if n mod i = 0
cnt += 1
if i <> n div i
cnt += 1
.
.
i += 1
.
return cnt
.
i = 1
while n < 100
if i mod cntdiv i = 0
write i & " "
n += 1
.
i += 1
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
This task uses [Tau_function#F.23]
<langsyntaxhighlight lang="fsharp">
// Tau number. Nigel Galloway: March 9th., 2021
Seq.initInfinite((+)1)|>Seq.filter(fun n->n%(tau n)=0)|>Seq.take 100|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 632 ⟶ 1,277:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<langsyntaxhighlight lang="factor">USING: assocs grouping io kernel lists lists.lazy math
math.functions math.primes.factors prettyprint sequences
sequences.extras ;
Line 645 ⟶ 1,290:
"The first 100 tau numbers are:" print
100 taus ltake list>array 10 group simple-table.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 662 ⟶ 1,307:
 
=={{header|Fermat}}==
<langsyntaxhighlight lang="fermat">Func Istau(t) =
if t<3 then Return(1) else
numdiv:=2;
Line 682 ⟶ 1,327:
if Divides(10, numtau) then !! fi;
fi;
od;</langsyntaxhighlight>
 
=={{header|Forth}}==
{{trans|C++}}
<langsyntaxhighlight lang="forth">: divisor_count ( n -- n )
1 >r
begin
Line 728 ⟶ 1,373:
 
100 print_tau_numbers
bye</langsyntaxhighlight>
 
{{out}}
Line 746 ⟶ 1,391:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">function numdiv( n as uinteger ) as uinteger
dim as uinteger c = 2
for i as uinteger = 2 to (n+1)\2
Line 767 ⟶ 1,412:
end if
i += 1
wend</langsyntaxhighlight>
{{out}}
<pre>1 2 8 9 12 18 24 36 40 56
Line 779 ⟶ 1,424:
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Frink}}==
<syntaxhighlight lang="frink">tau = {|x| x mod length[allFactors[x]] == 0}
println[formatTable[columnize[first[select[count[1], tau], 100], 10], "right"]]</syntaxhighlight>
{{out}}
<pre>
1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 820 ⟶ 1,482:
i++
}
}</langsyntaxhighlight>
 
{{out}}
Line 838 ⟶ 1,500:
 
=={{header|Haskell}}==
<langsyntaxhighlight Haskelllang="haskell">tau :: Integral a => a -> a
tau n | n <= 0 = error "Not a positive integer"
tau n = go 0 (1, 1)
Line 852 ⟶ 1,514:
isTau n = 0 == mod n (tau n)
 
main = print . take 100 . filter isTau $ [1..]</langsyntaxhighlight>
{{out}}
<pre>[1,2,8,9,12,18,24,36,40,56,60,72,80,84,88,96,104,108,128,132,136,152,156,180,184,204,225,228,232,240,248,252,276,288,296,328,344,348,360,372,376,384,396,424,441,444,448,450,468,472,480,488,492,504,516,536,560,564,568,584,600,612,625,632,636,640,664,672,684,708,712,720,732,776,792,804,808,824,828,852,856,864,872,876,880,882,896,904,936,948,972,996,1016,1040,1044,1048,1056,1068,1089,1096]</pre>
Line 859 ⟶ 1,521:
and we could also define Tau numbers in terms of a more general ''divisors'' function:
 
<langsyntaxhighlight lang="haskell">import Data.List (group, scanl)
import Data.List.Split (chunksOf)
import Data.Numbers.Primes (primeFactors)
Line 891 ⟶ 1,553:
 
justifyRight :: Int -> Char -> String -> String
justifyRight n c = (drop . length) <*> (replicate n c <>)</langsyntaxhighlight>
{{Out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 905 ⟶ 1,567:
 
=={{header|J}}==
 
{{needs-review|J|In [[Special: Diff/346769|revision 54A91]] the task has been qualified not contain τ-numbers. ‑‑[[User:Root|Root]] ([[User talk:Root|talk]]) 10:34, 11 November 2021 (UTC)}}
Implementation:
<pre>
<syntaxhighlight lang="j">
NB. use
tau_number=: 0 = (|~ tally_factors@>)
_25]\100{.(#~ tau_number&>) #\i.2000
tally_factors=: [: */ 1 + _&q:
</syntaxhighlight>
 
Explanation: _ q: produces a list of the exponents of the prime factors of a number. The product of 1 + this list is the number of positive factors of that number. We have a tau number if the remainder of the number divided by that factor count is zero.
 
In the task example, we generate a list of the first 2000 positive integers and then use an expression of the form (#~ test) which filters a list of numbers based on that test. We then extract the first 100 of these in a 4 row 25 column table.
 
Task example:
<syntaxhighlight lang="j">
(i.4 25){ (#~ tau_number) 1+i.2000
1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96 104 108 128 132 136 152 156 180 184
204 225 228 232 240 248 252 276 288 296 328 344 348 360 372 376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584 600 612 625 632 636 640 664 672 684 708 712 720 732 776 792
804 808 824 828 852 856 864 872 876 880 882 896 904 936 948 972 996 1016 1040 1044 1048 1056 1068 1089 1096
</syntaxhighlight>
 
NB. definitions
tau_number
0 = (|~ tally_factors)
tally_factors
[: */ [: >: [: {: __&q:
</pre>
 
=={{header|Java}}==
{{trans|D}}
<langsyntaxhighlight lang="java">public class Tau {
private static long divisorCount(long n) {
long total = 1;
Line 959 ⟶ 1,625:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>The first 100 tau numbers are:
Line 980 ⟶ 1,646:
 
See https://rosettacode.org/wiki/Sum_of_divisors#jq for the definition of `divisors` used here
<langsyntaxhighlight lang="jq">def count(s): reduce s as $x (0; .+1);
 
# For pretty-printing
Line 987 ⟶ 1,653:
n;
 
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;</langsyntaxhighlight>
'''The task'''
<langsyntaxhighlight lang="jq">def taus: range(1;infinite) | select(. % count(divisors) == 0);
 
# The first 100 Tau numbers:
[limit(100; taus)]
| nwise(10) | map(lpad(4)) | join(" ")</langsyntaxhighlight>
{{out}}
<pre>
Line 1,010 ⟶ 1,676:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Primes
 
function numfactors(n)
Line 1,032 ⟶ 1,698:
 
taunumbers()
</langsyntaxhighlight>{{out}}
<pre>
1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96 104 108 128 132
Line 1,043 ⟶ 1,709:
=={{header|Lua}}==
{{trans|C}}
<langsyntaxhighlight lang="lua">function divisor_count(n)
local total = 1
 
Line 1,082 ⟶ 1,748:
end
n = n + 1
end</langsyntaxhighlight>
{{out}}
<pre>The first 100 tau numbers are:
Line 1,091 ⟶ 1,757:
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|M2000 Interpreter}}==
 
<syntaxhighlight lang="m2000 interpreter">
module tau_numbers {
print "The first 100 tau numbers are:"
long n, num, limit=100, tau, m
while num < limit
n++:
tau=0
for m=1 to n{if n mod m=0 then tau++}
if n mod tau= 0 else continue
num++:if num mod 10 = 1 then print
print format$("{0::-5}",n);
end while
print
}
profiler
tau_numbers
print timecount
</syntaxhighlight>
{{out}}
<pre>
The first 100 tau numbers:
1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
 
=={{header|MAD}}==
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
INTERNAL FUNCTION(N)
Line 1,112 ⟶ 1,813:
 
VECTOR VALUES NUM = $I4*$
END OF PROGRAM </langsyntaxhighlight>
 
{{out}}
Line 1,218 ⟶ 1,919:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Take[Select[Range[10000], Divisible[#, Length[Divisors[#]]] &], 100]</langsyntaxhighlight>
{{out}}
<pre>{1,2,8,9,12,18,24,36,40,56,60,72,80,84,88,96,104,108,128,132,136,152,156,180,184,204,225,228,232,240,248,252,276,288,296,328,344,348,360,372,376,384,396,424,441,444,448,450,468,472,480,488,492,504,516,536,560,564,568,584,600,612,625,632,636,640,664,672,684,708,712,720,732,776,792,804,808,824,828,852,856,864,872,876,880,882,896,904,936,948,972,996,1016,1040,1044,1048,1056,1068,1089,1096}</pre>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
isTauNumber = function(n)
ans = 0
i = 1
while i * i <= n
if n % i == 0 then
ans += 1
j = floor(n / i)
if j != i then ans += 1
end if
i += 1
end while
return (n % ans) == 0
end function
 
tauNums = []
i = 1
while tauNums.len < 100
if isTauNumber(i) then tauNums.push(i)
i += 1
end while
 
print tauNums.join(", ")
</syntaxhighlight>
{{out}}
<pre>
1, 2, 8, 9, 12, 18, 24, 36, 40, 56, 60, 72, 80, 84, 88, 96, 104, 108, 128, 132, 136, 152, 156, 180, 184, 204, 225, 228, 232, 240, 248, 252, 276, 288, 296, 328, 344, 348, 360, 372, 376, 384, 396, 424, 441, 444, 448, 450, 468, 472, 480, 488, 492, 504, 516, 536, 560, 564, 568, 584, 600, 612, 625, 632, 636, 640, 664, 672, 684, 708, 712, 720, 732, 776, 792, 804, 808, 824, 828, 852, 856, 864, 872, 876, 880, 882, 896, 904, 936, 948, 972, 996, 1016, 1040, 1044, 1048, 1056, 1068, 1089, 1096
</pre>
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE TauNumbers;
FROM InOut IMPORT WriteCard, WriteLn;
 
CONST
MaxNum = 1100; (* enough to generate 100 Tau numbers *)
NumTau = 100; (* how many Tau numbers to generate *)
 
VAR DivCount: ARRAY [1..MaxNum] OF CARDINAL;
seen, n: CARDINAL;
 
(* Find the amount of divisors for each number beforehand *)
PROCEDURE CountDivisors;
VAR i, j: CARDINAL;
BEGIN
FOR i := 1 TO MaxNum DO
DivCount[i] := 1; (* every number is divisible by 1 *)
END;
FOR i := 2 TO MaxNum DO
j := i;
WHILE j <= MaxNum DO (* J is divisible by I *)
DivCount[j] := DivCount[j] + 1;
j := j + i; (* next multiple of i *)
END;
END;
END CountDivisors;
 
BEGIN
CountDivisors();
n := 1;
seen := 0;
WHILE seen < NumTau DO
IF n MOD DivCount[n] = 0 THEN
WriteCard(n, 5);
INC(seen);
IF seen MOD 10 = 0 THEN
WriteLn();
END;
END;
INC(n);
END;
END TauNumbers.</syntaxhighlight>
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import math, strutils
 
func divcount(n: Natural): Natural =
Line 1,244 ⟶ 2,030:
for i, n in tauNumbers:
stdout.write ($n).align(5)
if i mod 20 == 19: echo()</langsyntaxhighlight>
 
{{out}}
Line 1,253 ⟶ 2,039:
600 612 625 632 636 640 664 672 684 708 712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948 972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Oberon-2}}==
{{trans|Modula-2}}
<syntaxhighlight lang="oberon2">MODULE TauNumbers;
 
IMPORT Out;
 
CONST
MaxNum = 1100;
NumTau = 100;
 
VAR
divcount: ARRAY MaxNum OF LONGINT; (* enough to generate 100 Tau numbers *)
seen,n:LONGINT; (* how many Tau numbers to generate *)
 
(* Find the amount of divisors for each number beforehand *)
PROCEDURE CountDivisors;
VAR i,j:LONGINT;
BEGIN
FOR i := 0 TO LEN(divcount)-1 DO divcount[i] := 1 END;
FOR i := 2 TO LEN(divcount)-1 DO
j := i;
WHILE j <= LEN(divcount)-1 DO (* j is divisible by i *)
INC(divcount[j]);
INC(j,i) (* next multiple of i *)
END
END;
END CountDivisors;
BEGIN
CountDivisors;
n := 1;
seen := 0;
WHILE seen < NumTau DO
IF n MOD divcount[n] = 0 THEN
Out.Int(n,5);
INC(seen);
IF seen MOD 10 = 0 THEN Out.Ln END
END;
INC(n)
END
END TauNumbers.
</syntaxhighlight>
 
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
 
 
=={{header|PARI/GP}}==
{{trans|Mathematica}}
<syntaxhighlight lang="PARI/GP">
{
mylist = []; \\ Initialize an empty list
for (n=1, 10000, \\ Iterate from 1 to 10000
if (n % numdiv(n) == 0, \\ Check if n is divisible by the number of its divisors
mylist = concat(mylist, [n]); \\ If so, append n to the list
if (#mylist == 100, break); \\ Break the loop if we've collected 100 numbers
)
);
print1(mylist); \\ Return the list
}
</syntaxhighlight>
{{out}}
<pre>
[1, 2, 8, 9, 12, 18, 24, 36, 40, 56, 60, 72, 80, 84, 88, 96, 104, 108, 128, 132, 136, 152, 156, 180, 184, 204, 225, 228, 232, 240, 248, 252, 276, 288, 296, 328, 344, 348, 360, 372, 376, 384, 396, 424, 441, 444, 448, 450, 468, 472, 480, 488, 492, 504, 516, 536, 560, 564, 568, 584, 600, 612, 625, 632, 636, 640, 664, 672, 684, 708, 712, 720, 732, 776, 792, 804, 808, 824, 828, 852, 856, 864, 872, 876, 880, 882, 896, 904, 936, 948, 972, 996, 1016, 1040, 1044, 1048, 1056, 1068, 1089, 1096]
</pre>
 
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<langsyntaxhighlight lang="pascal">program Tau_number;
{$IFDEF Windows} {$APPTYPE CONSOLE} {$ENDIF}
function CountDivisors(n: NativeUint): integer;
Line 1,309 ⟶ 2,172:
writeln;
{$Ifdef Windows}readln;{$ENDIF}
end.</langsyntaxhighlight>
{{out|TIO.RUN}}
<pre>
Line 1,326 ⟶ 2,189:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 1,336 ⟶ 2,199:
 
say "Tau numbers - first 100:\n" .
((sprintf "@{['%5d' x 100]}", @x[0..100-1]) =~ s/(.{80})/$1\n/gr);</langsyntaxhighlight>
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96
Line 1,348 ⟶ 2,211:
=={{header|Phix}}==
=== imperative ===
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">found</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">found</span><span style="color: #0000FF;"><</span><span style="color: #000000;">100</span> <span style="color: #008080;">do</span>
Line 1,358 ⟶ 2,221:
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,374 ⟶ 2,237:
=== functional/memoised ===
same output
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #004080;">sequence</span> <span style="color: #000000;">tau_cache</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">tau</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
Line 1,388 ⟶ 2,251:
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%,6d"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">100</span><span style="color: #0000FF;">),</span><span style="color: #000000;">tau</span><span style="color: #0000FF;">)}),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">))</span>
<!--</langsyntaxhighlight>-->
 
=={{header|PILOT}}==
<syntaxhighlight lang="pilot">T :1
C :n=2
C :seen=1
C :max=100
*number
C :c=1
C :i=1
*divisor
C (n=i*(n/i)):c=c+1
C :i=i+1
J (i<=n/2):*divisor
T (n=c*(n/c)):#n
C (n=c*(n/c)):seen=seen+1
C :n=n+1
J (seen<max):*number
E :</syntaxhighlight>
{{out}}
<pre style='height:50ex;'>1
2
8
9
12
18
24
36
40
56
60
72
80
84
88
96
104
108
128
132
136
152
156
180
184
204
225
228
232
240
248
252
276
288
296
328
344
348
360
372
376
384
396
424
441
444
448
450
468
472
480
488
492
504
516
536
560
564
568
584
600
612
625
632
636
640
664
672
684
708
712
720
732
776
792
804
808
824
828
852
856
864
872
876
880
882
896
904
936
948
972
996
1016
1040
1044
1048
1056
1068
1089
1096</pre>
 
=={{header|PL/M}}==
<langsyntaxhighlight lang="plm">100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
Line 1,454 ⟶ 2,436:
 
CALL EXIT;
EOF</langsyntaxhighlight>
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 1,466 ⟶ 2,448:
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Prolog}}==
{{works with|GNU Prolog}}
{{works with|SWI Prolog}}
<syntaxhighlight lang="prolog">tau(N, T) :-
findall(M, (between(1, N, M), 0 is N mod M), Ms),
length(Ms, T).
 
tau_numbers(Limit, Ns) :-
findall(N, (between(1, Limit, N), tau(N, T), 0 is N mod T), Ns).
 
print_tau_numbers :-
tau_numbers(1100, Ns),
writeln("The first 100 tau numbers are:"),
forall(member(N, Ns), format("~d ", [N])).
 
:- print_tau_numbers.</syntaxhighlight>
 
=={{header|PureBasic}}==
{{trans|FreeBasic}}<lang PureBasic>OpenConsole()
<syntaxhighlight lang="purebasic">OpenConsole()
 
Procedure.i numdiv(n)
Line 1,487 ⟶ 2,487:
Wend
 
Input()</langsyntaxhighlight>
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 1,502 ⟶ 2,502:
=={{header|Python}}==
===Python: Procedural===
<langsyntaxhighlight Pythonlang="python">def tau(n):
assert(isinstance(n, int) and 0 < n)
ans, i, j = 0, 1, 1
Line 1,527 ⟶ 2,527:
ans.append(n)
n += 1
print(ans)</langsyntaxhighlight>
{{out}}
<pre>[1, 2, 8, 9, 12, 18, 24, 36, 40, 56, 60, 72, 80, 84, 88, 96, 104, 108, 128, 132, 136, 152, 156, 180, 184, 204, 225, 228, 232, 240, 248, 252, 276, 288, 296, 328, 344, 348, 360, 372, 376, 384, 396, 424, 441, 444, 448, 450, 468, 472, 480, 488, 492, 504, 516, 536, 560, 564, 568, 584, 600, 612, 625, 632, 636, 640, 664, 672, 684, 708, 712, 720, 732, 776, 792, 804, 808, 824, 828, 852, 856, 864, 872, 876, 880, 882, 896, 904, 936, 948, 972, 996, 1016, 1040, 1044, 1048, 1056, 1068, 1089, 1096]</pre>
Line 1,533 ⟶ 2,533:
===Python: Functional===
Composing pure functions, and defining a non-finite stream of Tau numbers in terms of a generic `divisors` function:
<langsyntaxhighlight lang="python">'''Tau numbers'''
 
from operator import mul
Line 1,663 ⟶ 2,663:
if __name__ == '__main__':
main()
</syntaxhighlight>
</lang>
{{Out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 1,680 ⟶ 2,680:
<code>factors</code> is defined at [[Factors of an integer#Quackery]].
 
<langsyntaxhighlight Quackerylang="quackery"> [ dup factors size mod 0 = ] is taunumber ( n --> b )
 
[] 0
Line 1,689 ⟶ 2,689:
[] swap
witheach [ number$ nested join ]
80 wrap$</langsyntaxhighlight>
 
{{out}}
Line 1,700 ⟶ 2,700:
 
=={{header|R}}==
<langsyntaxhighlight Rlang="rsplus">tau <- function(t)
{
results <- integer(0)
Line 1,717 ⟶ 2,717:
results
}
tau(100)</langsyntaxhighlight>
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
 
(define limit 100)
 
(define (divisor-count n)
(length (filter (λ (x) (zero? (remainder n x))) (range 1 (+ 1 n)))))
 
(define (display-tau-numbers (n 1) (count 1))
(when (<= count limit)
(if (zero? (remainder n (divisor-count n)))
(begin
(printf (~a n #:width 5 #:align 'right))
(when (zero? (remainder count 10))
(newline))
(display-tau-numbers (add1 n) (add1 count)))
(display-tau-numbers (add1 n) count))))
 
(printf "The first ~a Τau numbers are~n" limit)
(display-tau-numbers)
</syntaxhighlight>
{{out}}
<pre>
The first 100 Τau numbers are
1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
 
=={{header|Raku}}==
Line 1,723 ⟶ 2,760:
Yet more tasks that are tiny variations of each other. [[Tau function]], [[Tau number]], [[Sum of divisors]] and [[Product of divisors]] all use code with minimal changes. What the heck, post 'em all.
 
<syntaxhighlight lang="raku" perl6line>use Prime::Factor:ver<0.3.0+>;
use Lingua::EN::Numbers;
 
Line 1,740 ⟶ 2,777:
say "\nDivisor products - first 100:\n", # ID
(1..*).map({ [×] .&divisors })[^100]\ # the task
.batch(5)».&comma».fmt("%16s").join("\n"); # display formatting</langsyntaxhighlight>
{{out}}
<pre>Tau function - first 100:
Line 1,791 ⟶ 2,828:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX pgm displays N tau numbers, an integer divisible by the # of its divisors). */
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n= 100 /*Not specified? Then use the default.*/
Line 1,828 ⟶ 2,865:
else if j*j>x then leave /*only divide up to √ x */
end /*j*/ /* [↑] this form of DO loop is faster.*/
return #</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 1,847 ⟶ 2,884:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
see "The first 100 tau numbers are:" + nl + nl
 
Line 1,869 ⟶ 2,906:
ok
end
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,884 ⟶ 2,921:
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
 
=={{header|RPL}}==
The tau function has been translated from Python.
≪ → n
≪ 0 1 1 n √ '''FOR''' j
'''IF''' n j MOD NOT '''THEN'''
SWAP 1 + SWAP DROP n j / IP
'''IF''' DUP j ≠ '''THEN''' SWAP 1 + SWAP '''END'''
'''END'''
'''NEXT''' DROP
≫ ≫ 'TAU' STO
≪ { } 1 '''DO'''
'''IF''' DUP DUP TAU MOD NOT '''THEN''' SWAP OVER + SWAP '''END'''
1 +
'''UNTIL''' OVER SIZE 100 ≥ '''END''' DROP
≫ 'TAUNB' STO
{{out}}
<pre>
{ 1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96 104 108 128 132 136 152 156 180 184 204 225 228 232 240 248 252 276 288 296 328 344 348 360 372 376 384 396 424 441 444 448 450 468 472 480 488 492 504 516 536 560 564 568 584 600 612 625 632 636 640 664 672 684 708 712 720 732 776 792 804 808 824 828 852 856 864 872 876 880 882 896 904 936 948 972 996 1016 1040 1044 1048 1056 1068 1089 1096 }
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require 'prime'
 
taus = Enumerator.new do |y|
Line 1,897 ⟶ 2,955:
 
p taus.take(100)
</syntaxhighlight>
</lang>
{{out}}
<pre>[1, 2, 8, 9, 12, 18, 24, 36, 40, 56, 60, 72, 80, 84, 88, 96, 104, 108, 128, 132, 136, 152, 156, 180, 184, 204, 225, 228, 232, 240, 248, 252, 276, 288, 296, 328, 344, 348, 360, 372, 376, 384, 396, 424, 441, 444, 448, 450, 468, 472, 480, 488, 492, 504, 516, 536, 560, 564, 568, 584, 600, 612, 625, 632, 636, 640, 664, 672, 684, 708, 712, 720, 732, 776, 792, 804, 808, 824, 828, 852, 856, 864, 872, 876, 880, 882, 896, 904, 936, 948, 972, 996, 1016, 1040, 1044, 1048, 1056, 1068, 1089, 1096]
Line 1,903 ⟶ 2,961:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
/// Gets all divisors of a number, including itself
fn get_divisors(n: u32) -> Vec<u32> {
Line 1,935 ⟶ 2,993:
}
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,947 ⟶ 3,005:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func is_tau_number(n) {
n % n.sigma0 == 0
}
 
say is_tau_number.first(100).join(' ')</langsyntaxhighlight>
{{out}}
<pre>
Line 1,958 ⟶ 3,016:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
// See https://en.wikipedia.org/wiki/Divisor_function
Line 2,000 ⟶ 3,058:
}
n += 1
}</langsyntaxhighlight>
 
{{out}}
Line 2,016 ⟶ 3,074:
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
 
=={{header|Verilog}}==
<syntaxhighlight lang="verilog">module main;
integer n, m, num, limit, tau;
initial begin
$display("The first 100 tau numbers are:\n");
n = 0;
num = 0;
limit = 100;
 
while (num < limit) begin
n = n + 1;
tau = 0;
for (m = 1; m <= n; m=m+1) if (n % m == 0) tau = tau + 1;
if (n % tau == 0) begin
num = num + 1;
if (num % 5 == 1) $display("");
$write(n);
end
end
$finish ;
end
endmodule</syntaxhighlight>
 
 
=={{header|VTL-2}}==
<syntaxhighlight lang="vtl2">10 N=1100
20 I=1
30 :I)=1
40 I=I+1
50 #=N>I*30
60 I=2
70 J=I
80 :J)=:J)+1
90 J=J+I
100 #=N>J*80
110 I=I+1
120 #=N>I*70
130 C=0
140 I=1
150 #=I/:I)*0+0<%*210
160 ?=I
170 $=9
180 C=C+1
190 #=C/10*0+0<%*210
200 ?=""
210 I=I+1
220 #=C<100*150</syntaxhighlight>
{{out}}
<pre>1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
import "./fmt" for Fmt
 
System.print("The first 100 tau numbers are:")
Line 2,034 ⟶ 3,153:
}
i = i + 1
}</langsyntaxhighlight>
 
{{out}}
Line 2,049 ⟶ 3,168:
856 864 872 876 880 882 896 904 936 948
972 996 1,016 1,040 1,044 1,048 1,056 1,068 1,089 1,096
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">func Divs(N); \Return number of divisors of N
int N, D, C;
[C:= 0;
for D:= 1 to N do
if rem(N/D) = 0 then C:= C+1;
return C;
];
 
int C, N;
[Format(5, 0);
C:= 0; N:= 1;
loop [if rem(N/Divs(N)) = 0 then
[RlOut(0, float(N));
C:= C+1;
if rem(C/10) = 0 then CrLf(0);
if C >= 100 then quit;
];
N:= N+1;
];
]</syntaxhighlight>
 
{{out}}
<pre>
1 2 8 9 12 18 24 36 40 56
60 72 80 84 88 96 104 108 128 132
136 152 156 180 184 204 225 228 232 240
248 252 276 288 296 328 344 348 360 372
376 384 396 424 441 444 448 450 468 472
480 488 492 504 516 536 560 564 568 584
600 612 625 632 636 640 664 672 684 708
712 720 732 776 792 804 808 824 828 852
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
2,122

edits