Tau number: Difference between revisions
Added solution for Action! |
|||
(48 intermediate revisions by 22 users not shown) | |||
Line 17:
{{trans|Python}}
<
V ans = 0
V i = 1
Line 41:
ans.append(n)
n++
print(ans)</
{{out}}
Line 49:
=={{header|Action!}}==
<
CARD result,p,count
Line 89:
n==+1
OD
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Tau_number.png Screenshot from Atari 8-bit computer]
Line 102:
=={{header|ALGOL 68}}==
{{Trans|C++}}
<
# calculates the number of divisors of v #
PROC divisor count = ( INT v )INT:
Line 140:
OD
END
END</
{{out}}
<pre>
Line 157:
=={{header|ALGOL-M}}==
<
integer array dcount[1:1100];
Line 191:
i := i + 1;
end;
end</
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 207:
{{works with|Dyalog APL}}
<
{{out}}
Line 219:
=={{header|AppleScript}}==
<
if (n < 1) then return 0
set counter to 2
Line 248:
set output to output as text
set AppleScript's text item delimiters to astid
return output</
{{output}}
<
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"</
=={{header|Arturo}}==
<
found: 0
Line 271:
]
i: i + 1
]</
{{out}}
Line 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">
# syntax: GAWK -f TAU_NUMBER.AWK
BEGIN {
Line 310 ⟶ 357:
return(count)
}
</syntaxhighlight>
{{out}}
<pre>
Line 327 ⟶ 374:
=={{header|BASIC}}==
<syntaxhighlight lang="basic">10 DEFINT A-Z
20 S=0: N=1
30 C=1
Line 335 ⟶ 381:
60 N=N+1
70 IF S<100 THEN 30
80 END</
{{out}}
<pre> 1 2 8 9 12
18 24 36 40 56
Line 359 ⟶ 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}}==
<
// Count the divisors of 1..N
Line 393 ⟶ 739:
n := n + 1
$)
$)</
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 408 ⟶ 754:
=={{header|C}}==
{{trans|C++}}
<
unsigned int divisor_count(unsigned int n) {
Line 450 ⟶ 796:
return 0;
}</
{{out}}
<pre>The first 100 tau numbers are:
Line 465 ⟶ 811:
=={{header|C++}}==
<
#include <iostream>
Line 499 ⟶ 845:
}
}
}</
{{out}}
Line 515 ⟶ 861:
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">
internal class Program
{
private static void Main(string[] args)
{
long limit = 100;
Console.WriteLine($"The first {limit} tau numbers are:");
long count = 0;
for (long n = 1; count < limit; ++n)
{
if (IsTauNumber(n))
{
Console.Write($"{n, 6} ");
++count;
if (count % 10 == 0)
{
Console.WriteLine();
}
}
}
}
private static bool IsTauNumber(long n)
{
return n % DivisorCount(n) == 0;
}
private static long DivisorCount(long n)
{
long total = 1;
// Deal with powers of 2 first
for (; (n & 1) == 0; n >>= 1)
{
++total;
}
// Odd prime factors up to the square root
for (long p = 3; p * p <= n; p += 2)
{
long 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;
}
}
</syntaxhighlight>
{{out}}
<pre>
The first 100 tau 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|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}}==
<
# <nowiki>Numbered list item</nowiki>
# Get count of positive divisors of number
Line 550 ⟶ 1,093:
nums := nums + 1;
end if;
end loop;</
{{out}}
Line 565 ⟶ 1,108:
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++}}
<
uint divisor_count(uint n) {
Line 605 ⟶ 1,178:
}
}
}</
{{out}}
<pre>The first 100 tau numbers are:
Line 618 ⟶ 1,191:
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">
program Tau_number;
Line 669 ⟶ 1,271:
{$IFNDEF UNIX} readln; {$ENDIF}
end.</
=={{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 lang=text>
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]
<
// 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>
{{out}}
<pre>
Line 684 ⟶ 1,354:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<
math.functions math.primes.factors prettyprint sequences
sequences.extras ;
Line 697 ⟶ 1,367:
"The first 100 tau numbers are:" print
100 taus ltake list>array 10 group simple-table.
</syntaxhighlight>
{{out}}
<pre>
Line 714 ⟶ 1,384:
=={{header|Fermat}}==
<
if t<3 then Return(1) else
numdiv:=2;
Line 734 ⟶ 1,404:
if Divides(10, numtau) then !! fi;
fi;
od;</
=={{header|Forth}}==
{{trans|C++}}
<
1 >r
begin
Line 780 ⟶ 1,450:
100 print_tau_numbers
bye</
{{out}}
Line 798 ⟶ 1,468:
=={{header|FreeBASIC}}==
<
dim as uinteger c = 2
for i as uinteger = 2 to (n+1)\2
Line 819 ⟶ 1,489:
end if
i += 1
wend</
{{out}}
<pre>1 2 8 9 12 18 24 36 40 56
Line 831 ⟶ 1,501:
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}}==
<
import "fmt"
Line 872 ⟶ 1,559:
i++
}
}</
{{out}}
Line 890 ⟶ 1,577:
=={{header|Haskell}}==
<
tau n | n <= 0 = error "Not a positive integer"
tau n = go 0 (1, 1)
Line 904 ⟶ 1,591:
isTau n = 0 == mod n (tau n)
main = print . take 100 . filter isTau $ [1..]</
{{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 911 ⟶ 1,598:
and we could also define Tau numbers in terms of a more general ''divisors'' function:
<
import Data.List.Split (chunksOf)
import Data.Numbers.Primes (primeFactors)
Line 943 ⟶ 1,630:
justifyRight :: Int -> Char -> String -> String
justifyRight n c = (drop . length) <*> (replicate n c <>)</
{{Out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 957 ⟶ 1,644:
=={{header|J}}==
Implementation:
<syntaxhighlight lang="j">
tau_number=: 0 = (|~ tally_factors@>)
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>
=={{header|Java}}==
{{trans|D}}
<
private static long divisorCount(long n) {
long total = 1;
Line 1,011 ⟶ 1,702:
}
}
}</
{{out}}
<pre>The first 100 tau numbers are:
Line 1,032 ⟶ 1,723:
See https://rosettacode.org/wiki/Sum_of_divisors#jq for the definition of `divisors` used here
<
# For pretty-printing
Line 1,039 ⟶ 1,730:
n;
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;</
'''The task'''
<
# The first 100 Tau numbers:
[limit(100; taus)]
| nwise(10) | map(lpad(4)) | join(" ")</
{{out}}
<pre>
Line 1,062 ⟶ 1,753:
=={{header|Julia}}==
<
function numfactors(n)
Line 1,084 ⟶ 1,775:
taunumbers()
</
<pre>
1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96 104 108 128 132
Line 1,095 ⟶ 1,786:
=={{header|Lua}}==
{{trans|C}}
<
local total = 1
Line 1,134 ⟶ 1,825:
end
n = n + 1
end</
{{out}}
<pre>The first 100 tau numbers are:
Line 1,143 ⟶ 1,834:
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}}==
<
INTERNAL FUNCTION(N)
Line 1,164 ⟶ 1,890:
VECTOR VALUES NUM = $I4*$
END OF PROGRAM </
{{out}}
Line 1,270 ⟶ 1,996:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
{{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}}==
<
FROM InOut IMPORT WriteCard, WriteLn;
Line 1,316 ⟶ 2,072:
INC(n);
END;
END TauNumbers.</
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 1,330 ⟶ 2,086:
=={{header|Nim}}==
<
func divcount(n: Natural): Natural =
Line 1,351 ⟶ 2,107:
for i, n in tauNumbers:
stdout.write ($n).align(5)
if i mod 20 == 19: echo()</
{{out}}
Line 1,360 ⟶ 2,116:
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}}===
<
{$IFDEF Windows} {$APPTYPE CONSOLE} {$ENDIF}
function CountDivisors(n: NativeUint): integer;
Line 1,417 ⟶ 2,249:
writeln;
{$Ifdef Windows}readln;{$ENDIF}
end.</
{{out|TIO.RUN}}
<pre>
Line 1,431 ⟶ 2,263:
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
##
function DivisorsCount(n: integer) := Range(1,n).Count(i -> n.Divs(i));
var lst := new List<integer>;
var n := 1;
while lst.Count < 100 do
begin
if n.Divs(DivisorsCount(n)) then
lst.Add(n);
n += 1;
end;
lst.Println;
</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|Perl}}==
{{libheader|ntheory}}
<
use warnings;
use feature 'say';
Line 1,444 ⟶ 2,296:
say "Tau numbers - first 100:\n" .
((sprintf "@{['%5d' x 100]}", @x[0..100-1]) =~ s/(.{80})/$1\n/gr);</
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96
Line 1,456 ⟶ 2,308:
=={{header|Phix}}==
=== imperative ===
<!--<
<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,466 ⟶ 2,318:
<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>
<!--</
{{out}}
<pre>
Line 1,482 ⟶ 2,334:
=== functional/memoised ===
same output
<!--<
<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,496 ⟶ 2,348:
<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>
<!--</
=={{header|PILOT}}==
<
C :n=2
C :seen=1
Line 1,514 ⟶ 2,366:
C :n=n+1
J (seen<max):*number
E :</
{{out}}
<pre style='height:50ex;'>1
Line 1,618 ⟶ 2,470:
=={{header|PL/M}}==
<
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
Line 1,681 ⟶ 2,533:
CALL EXIT;
EOF</
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 1,693 ⟶ 2,545:
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}}
<syntaxhighlight lang="purebasic">OpenConsole()
Procedure.i numdiv(n)
Line 1,714 ⟶ 2,584:
Wend
Input()</
{{out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 1,729 ⟶ 2,599:
=={{header|Python}}==
===Python: Procedural===
<
assert(isinstance(n, int) and 0 < n)
ans, i, j = 0, 1, 1
Line 1,754 ⟶ 2,624:
ans.append(n)
n += 1
print(ans)</
{{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,760 ⟶ 2,630:
===Python: Functional===
Composing pure functions, and defining a non-finite stream of Tau numbers in terms of a generic `divisors` function:
<
from operator import mul
Line 1,890 ⟶ 2,760:
if __name__ == '__main__':
main()
</syntaxhighlight>
{{Out}}
<pre> 1 2 8 9 12 18 24 36 40 56
Line 1,907 ⟶ 2,777:
<code>factors</code> is defined at [[Factors of an integer#Quackery]].
<
[] 0
Line 1,916 ⟶ 2,786:
[] swap
witheach [ number$ nested join ]
80 wrap$</
{{out}}
Line 1,927 ⟶ 2,797:
=={{header|R}}==
<
{
results <- integer(0)
Line 1,944 ⟶ 2,814:
results
}
tau(100)</
=={{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,950 ⟶ 2,857:
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"
use Lingua::EN::Numbers;
Line 1,967 ⟶ 2,874:
say "\nDivisor products - first 100:\n", # ID
(1..*).map({ [×] .&divisors })[^100]\ # the task
.batch(5)».&comma».fmt("%16s").join("\n"); # display formatting</
{{out}}
<pre>Tau function - first 100:
Line 2,018 ⟶ 2,925:
=={{header|REXX}}==
Simplified, use the tau function of the respective task, ooRexx compatible
<syntaxhighlight lang="rexx">/*REXX pgm displays N tau numbers (integers divisible by the # of its divisors). */
If cols=='' | cols==',' Then cols= 10 /*Not specified? Then use the default. */
Say '-------+'center('' ,cols*(w+1),'-')
idx=1
nn=0
dd=''
Do j=1 Until nn==n
If j//tau(j)==0 Then Do
nn=nn+1
If nn//cols==0 Then Do
Say center(idx,7)'¦' substr(dd,2) /* display partial list To the terminal.*/
idx= idx+cols /* bump idx by number of cols */
dd=''
End
End
End
If dd\=='' Then Say center(idx,7)'¦' substr(dd,2) /*possible display rest */
Say '--------'center('' ,cols*(w+1),'-')
Exit 0
/*--------------------------------------------------------------------------------*/
commas: Parse Arg ?; Do jc=length(?)-3 To 1 by -3; ?=insert(',',?,jc); End; Return ?
/*--------------------------------------------------------------------------------*/
tau: Procedure
Parse Arg x
If x<6 Then
Return 2+(x==4)-(x==1)
tau=0
odd=x//2
Do j=1 by 1 While j*j<x
If odd &
If x//j==0 Then /* If no remainder,Then found a divisor*/
tau=tau+2 /* bump n of divisors */
End
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
-------+----------------------------------------------------------------------
1
11
21
31
41
51
61
71
81
91
------------------------------------------------------------------------------</pre>
=={{header|Ring}}==
<
see "The first 100 tau numbers are:" + nl + nl
Line 2,096 ⟶ 3,008:
ok
end
</syntaxhighlight>
Output:
<pre>
Line 2,111 ⟶ 3,023:
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}}==
<
taus = Enumerator.new do |y|
Line 2,124 ⟶ 3,057:
p taus.take(100)
</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]
Line 2,130 ⟶ 3,063:
=={{header|Rust}}==
<
/// Gets all divisors of a number, including itself
fn get_divisors(n: u32) -> Vec<u32> {
Line 2,162 ⟶ 3,095:
}
</syntaxhighlight>
{{out}}
<pre>
Line 2,174 ⟶ 3,107:
=={{header|Sidef}}==
<
n % n.sigma0 == 0
}
say is_tau_number.first(100).join(' ')</
{{out}}
<pre>
Line 2,185 ⟶ 3,118:
=={{header|Swift}}==
<
// See https://en.wikipedia.org/wiki/Divisor_function
Line 2,227 ⟶ 3,160:
}
n += 1
}</
{{out}}
Line 2,243 ⟶ 3,176:
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}}
<
import "./fmt" for Fmt
System.print("The first 100 tau numbers are:")
Line 2,261 ⟶ 3,255:
}
i = i + 1
}</
{{out}}
Line 2,276 ⟶ 3,270:
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>
|
Latest revision as of 08:11, 23 July 2024
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
A Tau number is a positive integer divisible by the count of its positive divisors.
- Task
Show the first 100 Tau numbers. The numbers shall be generated during run-time (i.e. the code may not contain string literals, sets/arrays of integers, or alike).
- Related task
11l
F tau(n)
V ans = 0
V i = 1
V j = 1
L i * i <= n
I 0 == n % i
ans++
j = n I/ i
I j != i
ans++
i++
R ans
F is_tau_number(n)
I n <= 0
R 0B
R 0 == n % tau(n)
V n = 1
[Int] ans
L ans.len < 100
I is_tau_number(n)
ans.append(n)
n++
print(ans)
- Output:
[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]
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
- Output:
Screenshot from Atari 8-bit computer
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
ALGOL 68
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:
BEGIN
INT total := 1, n := v;
# Deal with powers of 2 first #
WHILE NOT ODD n DO
total +:= 1;
n OVERAB 2
OD;
# Odd prime factors up to the square root #
INT p := 1;
WHILE p +:= 2;
( p * p ) <= n
DO
INT count := 1;
WHILE n MOD p = 0 DO
count +:= 1;
n OVERAB p
OD;
total *:= count
OD;
# If n > 1 then it's prime #
IF n > 1 THEN total *:= 2 FI;
total
END # divisor count #;
BEGIN
INT tau limit = 100;
INT tau count := 0;
print( ( "The first ", whole( tau limit, 0 ), " tau numbers:", newline ) );
FOR n WHILE tau count < tau limit DO
IF n MOD divisor count( n ) = 0 THEN
tau count +:= 1;
print( ( whole( n, -6 ) ) );
IF tau count MOD 10 = 0 THEN print( ( newline ) ) FI
FI
OD
END
END
- Output:
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
ALGOL-M
begin
integer array dcount[1:1100];
integer i, j, n;
integer function mod(a,b);
integer a,b;
mod := a-a/b*b;
% Calculate counts of divisors for 1 .. 1100 %
for i := 1 step 1 until 1100 do dcount[i] := 1;
for i := 2 step 1 until 1100 do
begin
j := i;
while j <= 1100 do
begin
dcount[j] := dcount[j] + 1;
j := j + i;
end;
end;
n := 0;
i := 1;
while n < 100 do
begin
if mod(i, dcount[i])=0 then
begin
if mod(n, 10)=0
then write(i)
else writeon(i);
n := n + 1;
end;
i := i + 1;
end;
end
- Output:
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
APL
(⊢(/⍨)(0=(0+.=⍳|⊢)|⊢)¨)⍳ 1096
- Output:
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
AppleScript
on factorCount(n)
if (n < 1) then return 0
set counter to 2
set sqrt to n ^ 0.5
if (sqrt mod 1 = 0) then set counter to 1
repeat with i from (sqrt div 1) to 2 by -1
if (n mod i = 0) then set counter to counter + 2
end repeat
return counter
end factorCount
-- Task code:
local output, n, counter, astid
set output to {"First 100 tau numbers:"}
set n to 0
set counter to 0
repeat until (counter = 100)
set n to n + 1
if (n mod (factorCount(n)) = 0) then
set counter to counter + 1
if (counter mod 20 = 1) then set end of output to linefeed
set end of output to text -5 thru -1 of (" " & n)
end if
end repeat
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set output to output as text
set AppleScript's text item delimiters to astid
return output
- Output:
"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"
Arturo
tau: function [x] -> size factors x
found: 0
i:1
while [found<100][
if 0 = i % tau i [
prints pad to :string i 5
found: found + 1
if 0 = found % 10 -> print ""
]
i: i + 1
]
- Output:
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
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);
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
}
- Output:
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
AWK
# syntax: GAWK -f TAU_NUMBER.AWK
BEGIN {
print("The first 100 tau numbers:")
while (count < 100) {
i++
if (i % count_divisors(i) == 0) {
printf("%4d ",i)
if (++count % 10 == 0) {
printf("\n")
}
}
}
exit(0)
}
function count_divisors(n, count,i) {
for (i=1; i*i<=n; i++) {
if (n % i == 0) {
count += (i == n / i) ? 1 : 2
}
}
return(count)
}
- Output:
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
BASIC
10 DEFINT A-Z
20 S=0: N=1
30 C=1
40 IF N<>1 THEN FOR I=1 TO N/2: C=C-(N MOD I=0): NEXT
50 IF N MOD C=0 THEN PRINT N,: S=S+1
60 N=N+1
70 IF S<100 THEN 30
80 END
- Output:
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
Applesoft BASIC
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
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
Chipmunk Basic
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
Gambas
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
GW-BASIC
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
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
Minimal BASIC
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
MSX Basic
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
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
Run BASIC
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
True BASIC
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
Tiny BASIC
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
XBasic
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
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
BCPL
get "libhdr"
// Count the divisors of 1..N
let divcounts(v, n) be
$( // Every positive number is divisible by 1
for i=1 to n do v!i := 1;
for i=2 to n do
$( let j = i
while j <= n do
$( // J is divisible by I
v!j := v!j + 1
j := j + i
$)
$)
$)
// Given a stored vector of divisors counts, is a number a tau number?
let tau(v, i) = i rem v!i = 0
let start() be
$( let dvec = vec 1100
let n, seen = 1, 0
divcounts(dvec, 1100) // find amount of divisors for each number
while seen < 100 do
$( if tau(dvec, n) then
$( writed(n, 5)
seen := seen + 1
if seen rem 10 = 0 then wrch('*N')
$)
n := n + 1
$)
$)
- Output:
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
C
#include <stdio.h>
unsigned int divisor_count(unsigned int n) {
unsigned int total = 1;
unsigned int p;
// Deal with powers of 2 first
for (; (n & 1) == 0; n >>= 1) {
++total;
}
// Odd prime factors up to the square root
for (p = 3; p * p <= n; p += 2) {
unsigned 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;
}
int main() {
const unsigned int limit = 100;
unsigned int count = 0;
unsigned int n;
printf("The first %d tau numbers are:\n", limit);
for (n = 1; count < limit; ++n) {
if (n % divisor_count(n) == 0) {
printf("%6d", n);
++count;
if (count % 10 == 0) {
printf("\n");
}
}
}
return 0;
}
- Output:
The first 100 tau 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
C++
#include <iomanip>
#include <iostream>
// See https://en.wikipedia.org/wiki/Divisor_function
unsigned int divisor_count(unsigned int n) {
unsigned 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 (unsigned int p = 3; p * p <= n; p += 2) {
unsigned 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;
}
int main() {
const unsigned int limit = 100;
std::cout << "The first " << limit << " tau numbers are:\n";
unsigned int count = 0;
for (unsigned int n = 1; count < limit; ++n) {
if (n % divisor_count(n) == 0) {
std::cout << std::setw(6) << n;
++count;
if (count % 10 == 0)
std::cout << '\n';
}
}
}
- Output:
The first 100 tau 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
C#
internal class Program
{
private static void Main(string[] args)
{
long limit = 100;
Console.WriteLine($"The first {limit} tau numbers are:");
long count = 0;
for (long n = 1; count < limit; ++n)
{
if (IsTauNumber(n))
{
Console.Write($"{n, 6} ");
++count;
if (count % 10 == 0)
{
Console.WriteLine();
}
}
}
}
private static bool IsTauNumber(long n)
{
return n % DivisorCount(n) == 0;
}
private static long DivisorCount(long n)
{
long total = 1;
// Deal with powers of 2 first
for (; (n & 1) == 0; n >>= 1)
{
++total;
}
// Odd prime factors up to the square root
for (long p = 3; p * p <= n; p += 2)
{
long 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;
}
}
- Output:
The first 100 tau 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
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)))))
- Output:
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
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
- Output:
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
Cowgol
include "cowgol.coh";
# <nowiki>Numbered list item</nowiki>
# Get count of positive divisors of number
sub pos_div(num: uint16): (count: uint16) is
count := 1;
if num != 1 then
var cur: uint16 := 1;
while cur <= num/2 loop
if num % cur == 0 then
count := count + 1;
end if;
cur := cur + 1;
end loop;
end if;
end sub;
# Print first 100 Tau numbers
var nums: uint8 := 0;
var cur: uint16 := 0;
var col: uint16 := 10;
while nums < 100 loop
cur := cur + 1;
if cur % pos_div(cur) == 0 then
print_i16(cur);
col := col - 1;
if col == 0 then
print_nl();
col := 10;
else
print_char('\t');
end if;
nums := nums + 1;
end if;
end loop;
- Output:
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
Craft 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
- Output:
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
D
import std.stdio;
uint divisor_count(uint n) {
uint total = 1;
// Deal with powers of 2 first
for (; (n & 1) == 0; n >>= 1) {
++total;
}
// Odd prime factors up to the square root
for (uint p = 3; p * p <= n; p += 2) {
uint 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() {
immutable limit = 100;
writeln("The first ", limit, " tau numbers are:");
uint count = 0;
for (uint n = 1; count < limit; ++n) {
if (n % divisor_count(n) == 0) {
writef("%6d", n);
++count;
if (count % 10 == 0) {
writeln;
}
}
}
}
- Output:
The first 100 tau 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
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++;
}
}
}
Delphi
program Tau_number;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
function CountDivisors(n: Integer): Integer;
begin
Result := 0;
var i := 1;
var k := 2;
if (n mod 2) = 0 then
k := 1;
while i * i <= n do
begin
if (n mod i) = 0 then
begin
inc(Result);
var j := n div i;
if j <> i then
inc(Result);
end;
inc(i, k);
end;
end;
begin
Writeln('The first 100 tau numbers are:');
var count := 0;
var i := 1;
while count < 100 do
begin
var tf := CountDivisors(i);
if i mod tf = 0 then
begin
write(format('%4d ', [i]));
inc(count);
if count mod 10 = 0 then
writeln;
end;
inc(i);
end;
{$IFNDEF UNIX} readln; {$ENDIF}
end.
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
- Output:
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
EasyLang
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
.
F#
This task uses [Tau_function#F.23]
// 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 ""
- Output:
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
Factor
USING: assocs grouping io kernel lists lists.lazy math
math.functions math.primes.factors prettyprint sequences
sequences.extras ;
: tau ( n -- count ) group-factors values [ 1 + ] map-product ;
: tau? ( n -- ? ) dup tau divisor? ;
: taus ( -- list ) 1 lfrom [ tau? ] lfilter ;
! Task
"The first 100 tau numbers are:" print
100 taus ltake list>array 10 group simple-table.
- Output:
The first 100 tau 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
Fermat
Func Istau(t) =
if t<3 then Return(1) else
numdiv:=2;
for q = 2 to t\2 do
if Divides(q, t) then numdiv:=numdiv+1 fi;
od;
if Divides(numdiv, t)=1 then Return(1) else Return(0) fi;
fi;
.;
numtau:=0;
i:=0;
while numtau<100 do
i:=i+1;
if Istau(i) = 1 then
numtau:=numtau+1;
!(i,' ');
if Divides(10, numtau) then !! fi;
fi;
od;
Forth
: divisor_count ( n -- n )
1 >r
begin
dup 2 mod 0=
while
r> 1+ >r
2/
repeat
3
begin
2dup dup * >=
while
1 >r
begin
2dup mod 0=
while
r> 1+ >r
tuck / swap
repeat
2r> * >r
2 +
repeat
drop 1 > if r> 2* else r> then ;
: print_tau_numbers ( n -- )
." The first " dup . ." tau numbers are:" cr
0 >r
1
begin
over r@ >
while
dup dup divisor_count mod 0= if
dup 6 .r
r> 1+
dup 10 mod 0= if cr else space then
>r
then
1+
repeat
2drop rdrop ;
100 print_tau_numbers
bye
- Output:
The first 100 tau 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
FreeBASIC
function numdiv( n as uinteger ) as uinteger
dim as uinteger c = 2
for i as uinteger = 2 to (n+1)\2
if n mod i = 0 then c += 1
next i
return c
end function
function istau( n as uinteger ) as boolean
if n = 1 then return true
if n mod numdiv(n) = 0 then return true else return false
end function
dim as uinteger c = 0, i=1
while c < 100
if istau(i) then
print i,
c += 1
if c mod 10 = 0 then print
end if
i += 1
wend
- Output:
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
Frink
tau = {|x| x mod length[allFactors[x]] == 0}
println[formatTable[columnize[first[select[count[1], tau], 100], 10], "right"]]
- Output:
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
Go
package main
import "fmt"
func countDivisors(n int) int {
count := 0
i := 1
k := 2
if n%2 == 0 {
k = 1
}
for i*i <= n {
if n%i == 0 {
count++
j := n / i
if j != i {
count++
}
}
i += k
}
return count
}
func main() {
fmt.Println("The first 100 tau numbers are:")
count := 0
i := 1
for count < 100 {
tf := countDivisors(i)
if i%tf == 0 {
fmt.Printf("%4d ", i)
count++
if count%10 == 0 {
fmt.Println()
}
}
i++
}
}
- Output:
The first 100 tau 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
Haskell
tau :: Integral a => a -> a
tau n | n <= 0 = error "Not a positive integer"
tau n = go 0 (1, 1)
where
yo i = (i, i * i)
go r (i, ii)
| n < ii = r
| n == ii = r + 1
| 0 == mod n i = go (r + 2) (yo $ i + 1)
| otherwise = go r (yo $ i + 1)
isTau :: Integral a => a -> Bool
isTau n = 0 == mod n (tau n)
main = print . take 100 . filter isTau $ [1..]
- Output:
[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]
and we could also define Tau numbers in terms of a more general divisors function:
import Data.List (group, scanl)
import Data.List.Split (chunksOf)
import Data.Numbers.Primes (primeFactors)
----------------------- TAU NUMBERS ----------------------
tauNumbers :: [Int]
tauNumbers =
filter
((0 ==) . (rem <*> (length . divisors)))
[1 ..]
--------------------------- TEST -------------------------
main :: IO ()
main =
let xs = take 100 $ fmap show tauNumbers
w = length $ last xs
in (putStrLn . unlines) $
unwords . fmap (justifyRight w ' ')
<$> chunksOf 10 xs
------------------------- GENERIC ------------------------
divisors :: Int -> [Int]
divisors =
foldr
(flip ((<*>) . fmap (*)) . scanl (*) 1)
[1]
. group
. primeFactors
justifyRight :: Int -> Char -> String -> String
justifyRight n c = (drop . length) <*> (replicate n c <>)
- Output:
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
J
Implementation:
tau_number=: 0 = (|~ tally_factors@>)
tally_factors=: [: */ 1 + _&q:
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:
(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
Java
public class Tau {
private static long divisorCount(long n) {
long total = 1;
// Deal with powers of 2 first
for (; (n & 1) == 0; n >>= 1) {
++total;
}
// Odd prime factors up to the square root
for (long p = 3; p * p <= n; p += 2) {
long 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;
}
public static void main(String[] args) {
final long limit = 100;
System.out.printf("The first %d tau numbers are:%n", limit);
long count = 0;
for (long n = 1; count < limit; ++n) {
if (n % divisorCount(n) == 0) {
System.out.printf("%6d", n);
++count;
if (count % 10 == 0) {
System.out.println();
}
}
}
}
}
- Output:
The first 100 tau 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
jq
Works with gojq, the Go implementation of jq
Preliminaries
See https://rosettacode.org/wiki/Sum_of_divisors#jq for the definition of `divisors` used here
def count(s): reduce s as $x (0; .+1);
# For pretty-printing
def nwise($n):
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
n;
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
The task
def taus: range(1;infinite) | select(. % count(divisors) == 0);
# The first 100 Tau numbers:
[limit(100; taus)]
| nwise(10) | map(lpad(4)) | join(" ")
- Output:
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
Julia
using Primes
function numfactors(n)
f = [one(n)]
for (p, e) in factor(n)
f = reduce(vcat, [f * p^j for j in 1:e], init = f)
end
length(f)
end
function taunumbers(toget = 100)
n = 0
for i in 1:100000000
if i % numfactors(i) == 0
n += 1
print(rpad(i, 5), n % 20 == 0 ? " \n" : "")
n == toget && break
end
end
end
taunumbers()
- Output:
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
Lua
function divisor_count(n)
local total = 1
-- Deal with powers of 2 first
while (n & 1) == 0 do
total = total + 1
n = n >> 1
end
-- Odd prime factors up to the square root
local p = 3
while p * p <= n do
local count = 1
while n % p == 0 do
count = count + 1
n = math.floor(n / p)
end
total = total * count
p = p + 2
end
-- If n > 1 then it's prime
if n > 1 then
total = total * 2
end
return total
end
local limit = 100
local count = 0
print("The first " .. limit .. " tau numbers are:")
local n = 1
while count < limit do
if n % divisor_count(n) == 0 then
io.write(string.format("%6d", n))
count = count + 1
if count % 10 == 0 then
print()
end
end
n = n + 1
end
- Output:
The first 100 tau numbers are: 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
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
- Output:
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
MAD
NORMAL MODE IS INTEGER
INTERNAL FUNCTION(N)
ENTRY TO POSDIV.
COUNT = 1
THROUGH DIV, FOR I=2, 1, I.G.N
DIV WHENEVER N/I*I.E.N, COUNT = COUNT+1
FUNCTION RETURN COUNT
END OF FUNCTION
SEEN=0
THROUGH TAU, FOR X=1, 1, SEEN.GE.100
DIVS=POSDIV.(X)
WHENEVER X/DIVS*DIVS.E.X
PRINT FORMAT NUM,X
SEEN = SEEN+1
TAU END OF CONDITIONAL
VECTOR VALUES NUM = $I4*$
END OF PROGRAM
- Output:
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
Mathematica /Wolfram Language
Take[Select[Range[10000], Divisible[#, Length[Divisors[#]]] &], 100]
- Output:
{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}
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(", ")
- Output:
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
Modula-2
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.
- Output:
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
Nim
import math, strutils
func divcount(n: Natural): Natural =
for i in 1..sqrt(n.toFloat).int:
if n mod i == 0:
inc result
if n div i != i: inc result
var count = 0
var n = 1
var tauNumbers: seq[Natural]
while true:
if n mod divcount(n) == 0:
tauNumbers.add n
inc count
if count == 100: break
inc n
echo "First 100 tau numbers:"
for i, n in tauNumbers:
stdout.write ($n).align(5)
if i mod 20 == 19: echo()
- Output:
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
Oberon-2
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.
- Output:
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
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
}
- Output:
[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]
Pascal
Free Pascal
program Tau_number;
{$IFDEF Windows} {$APPTYPE CONSOLE} {$ENDIF}
function CountDivisors(n: NativeUint): integer;
//tau function
var
q, p, cnt, divcnt: NativeUint;
begin
divCnt := 1;
if n > 1 then
begin
cnt := 1;
while not (Odd(n)) do
begin
n := n shr 1;
divCnt+= cnt;
end;
p := 3;
while p * p <= n do
begin
cnt := divCnt;
q := n div p;
while q * p = n do
begin
n := q;
q := n div p;
divCnt+= cnt;
end;
Inc(p, 2);
end;
if n <> 1 then
divCnt += divCnt;
end;
CountDivisors := divCnt;
end;
const
UPPERLIMIT = 100;
var
cnt,n: NativeUint;
begin
cnt := 0;
n := 1;
repeat
if n MOD CountDivisors(n) = 0 then
Begin
write(n:5);
inc(cnt);
if cnt Mod 10 = 0 then
writeln;
end;
inc(n);
until cnt >= UPPERLIMIT;
writeln;
{$Ifdef Windows}readln;{$ENDIF}
end.
- TIO.RUN:
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
PascalABC.NET
##
function DivisorsCount(n: integer) := Range(1,n).Count(i -> n.Divs(i));
var lst := new List<integer>;
var n := 1;
while lst.Count < 100 do
begin
if n.Divs(DivisorsCount(n)) then
lst.Add(n);
n += 1;
end;
lst.Println;
- Output:
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
Perl
use strict;
use warnings;
use feature 'say';
use ntheory 'divisors';
my(@x,$n);
do { push(@x,$n) unless $n % scalar(divisors(++$n)) } until 100 == @x;
say "Tau numbers - first 100:\n" .
((sprintf "@{['%5d' x 100]}", @x[0..100-1]) =~ s/(.{80})/$1\n/gr);
- Output:
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
Phix
imperative
integer n = 1, found = 0 while found<100 do if remainder(n,length(factors(n,1)))=0 then found += 1 printf(1,"%,6d",n) if remainder(found,10)=0 then puts(1,"\n") end if end if n += 1 end while
- Output:
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
functional/memoised
same output
sequence tau_cache = {1} function tau(integer n) while n>length(tau_cache) do integer nt = tau_cache[$]+1 while remainder(nt,length(factors(nt,1)))!=0 do nt += 1 end while tau_cache &= nt end while return tau_cache[n] end function puts(1,join_by(apply(true,sprintf,{{"%,6d"},apply(tagset(100),tau)}),1,10,""))
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 :
- Output:
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
PL/M
100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
/* PRINT NUMBER RIGHT-ALIGNED IN 7 POSITIONS */
PRINT$NUMBER: PROCEDURE (N);
DECLARE S (7) BYTE INITIAL (' .....$');
DECLARE N ADDRESS, I BYTE;
I = 6;
DIGIT:
I = I - 1;
S(I) = N MOD 10 + '0';
N = N / 10;
IF N > 0 THEN GO TO DIGIT;
DO WHILE I <> 0;
I = I - 1;
S(I) = ' ';
END;
CALL PRINT(.S);
END PRINT$NUMBER;
/* COUNT AND STORE AMOUNT OF DIVISORS FOR 1..N AT VEC */
COUNT$DIVS: PROCEDURE (VEC, N);
DECLARE (VEC, N, V BASED VEC) ADDRESS;
DECLARE (I, J) ADDRESS;
DO I=1 TO N;
V(I) = 1;
END;
DO I=2 TO N;
J = I;
DO WHILE J <= N;
V(J) = V(J) + 1;
J = J + I;
END;
END;
END COUNT$DIVS;
/* GIVEN VECTOR OF COUNT OF DIVISORS, SEE IF N IS A TAU NUMBER */
TAU: PROCEDURE (VEC, N) BYTE;
DECLARE (VEC, N, V BASED VEC) ADDRESS;
RETURN N MOD V(N) = 0;
END TAU;
DECLARE AMOUNT LITERALLY '100';
DECLARE LIMIT LITERALLY '1100';
DECLARE SEEN BYTE INITIAL (0);
DECLARE N ADDRESS INITIAL (1);
CALL COUNT$DIVS(.MEMORY, LIMIT);
DO WHILE SEEN < AMOUNT;
IF TAU(.MEMORY, N) THEN DO;
CALL PRINT$NUMBER(N);
SEEN = SEEN + 1;
IF SEEN MOD 10 = 0 THEN CALL PRINT(.(13,10,'$'));
END;
N = N + 1;
END;
CALL EXIT;
EOF
- Output:
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
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.
PureBasic
OpenConsole()
Procedure.i numdiv(n)
c=2
For i=2 To (n+1)/2 : If n%i=0 : c+1 : EndIf : Next
ProcedureReturn c
EndProcedure
Procedure.b istau(n)
If n=1 : ProcedureReturn #True : EndIf
If n%numdiv(n)=0 : ProcedureReturn #True : Else : ProcedureReturn #False : EndIf
EndProcedure
c=0 : i=1
While c<100
If istau(i) : Print(RSet(Str(i),4)+#TAB$) : c+1 : If c%10=0 : PrintN("") : EndIf: EndIf
i+1
Wend
Input()
- Output:
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
Python
Python: Procedural
def tau(n):
assert(isinstance(n, int) and 0 < n)
ans, i, j = 0, 1, 1
while i*i <= n:
if 0 == n%i:
ans += 1
j = n//i
if j != i:
ans += 1
i += 1
return ans
def is_tau_number(n):
assert(isinstance(n, int))
if n <= 0:
return False
return 0 == n%tau(n)
if __name__ == "__main__":
n = 1
ans = []
while len(ans) < 100:
if is_tau_number(n):
ans.append(n)
n += 1
print(ans)
- Output:
[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]
Python: Functional
Composing pure functions, and defining a non-finite stream of Tau numbers in terms of a generic `divisors` function:
'''Tau numbers'''
from operator import mul
from math import floor, sqrt
from functools import reduce
from itertools import (
accumulate, chain, count,
groupby, islice, product
)
# tauNumbers :: Generator [Int]
def tauNumbers():
'''Positive integers divisible by the
count of their positive divisors.
'''
return (
n for n in count(1)
if 0 == n % len(divisors(n))
)
# ------------------------- TEST -------------------------
# main :: IO ()
def main():
'''The first hundred Tau numbers.
'''
xs = take(100)(
tauNumbers()
)
w = len(str(xs[-1]))
print('\n'.join([
' '.join([
str(cell).rjust(w, ' ') for cell in row
])
for row in chunksOf(10)(xs)
]))
# ----------------------- GENERIC ------------------------
# chunksOf :: Int -> [a] -> [[a]]
def chunksOf(n):
'''A series of lists of length n, subdividing the
contents of xs. Where the length of xs is not evenly
divible, the final list will be shorter than n.
'''
def go(xs):
return (
xs[i:n + i] for i in range(0, len(xs), n)
) if 0 < n else None
return go
# divisors :: Int -> [Int]
def divisors(n):
'''The ordered divisors of n.
'''
def go(a, x):
return [a * b for a, b in product(
a,
accumulate(chain([1], x), mul)
)]
return sorted(
reduce(go, [
list(g) for _, g
in groupby(primeFactors(n))
], [1])
) if 1 < n else [1]
# primeFactors :: Int -> [Int]
def primeFactors(n):
'''A list of the prime factors of n.
'''
def f(qr):
r = qr[1]
return step(r), 1 + r
def step(x):
return 1 + (x << 2) - ((x >> 1) << 1)
def go(x):
root = floor(sqrt(x))
def p(qr):
q = qr[0]
return root < q or 0 == (x % q)
q = until(p)(f)(
(2 if 0 == x % 2 else 3, 1)
)[0]
return [x] if q > root else [q] + go(x // q)
return go(n)
# take :: Int -> [a] -> [a]
# take :: Int -> String -> String
def take(n):
'''The prefix of xs of length n,
or xs itself if n > length xs.
'''
def go(xs):
return (
xs[0:n]
if isinstance(xs, (list, tuple))
else list(islice(xs, n))
)
return go
# until :: (a -> Bool) -> (a -> a) -> a -> a
def until(p):
'''The result of repeatedly applying f until p holds.
The initial seed value is x.
'''
def go(f):
def g(x):
v = x
while not p(v):
v = f(v)
return v
return g
return go
# MAIN ---
if __name__ == '__main__':
main()
- Output:
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
Quackery
factors
is defined at Factors of an integer#Quackery.
[ dup factors size mod 0 = ] is taunumber ( n --> b )
[] 0
[ 1+ dup taunumber if
[ tuck join swap ]
over size 100 = until ]
drop
[] swap
witheach [ number$ nested join ]
80 wrap$
- Output:
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
R
tau <- function(t)
{
results <- integer(0)
resultsCount <- 0
n <- 1
while(resultsCount != t)
{
condition <- function(n) (n %% length(c(Filter(function(x) n %% x == 0, seq_len(n %/% 2)), n))) == 0
if(condition(n))
{
resultsCount <- resultsCount + 1
results[resultsCount] <- n
}
n <- n + 1
}
results
}
tau(100)
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)
- Output:
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
Raku
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.
use Prime::Factor:ver<0.3.0+>;
use Lingua::EN::Numbers;
say "\nTau function - first 100:\n", # ID
(1..*).map({ +.&divisors })[^100]\ # the task
.batch(20)».fmt("%3d").join("\n"); # display formatting
say "\nTau numbers - first 100:\n", # ID
(1..*).grep({ $_ %% +.&divisors })[^100]\ # the task
.batch(10)».&comma».fmt("%5s").join("\n"); # display formatting
say "\nDivisor sums - first 100:\n", # ID
(1..*).map({ [+] .&divisors })[^100]\ # the task
.batch(20)».fmt("%4d").join("\n"); # display formatting
say "\nDivisor products - first 100:\n", # ID
(1..*).map({ [×] .&divisors })[^100]\ # the task
.batch(5)».&comma».fmt("%16s").join("\n"); # display formatting
- Output:
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
REXX
Simplified, use the tau function of the respective task, ooRexx compatible
/*REXX pgm displays N tau numbers (integers 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. */
If cols=='' | cols==',' Then cols= 10 /*Not specified? Then use the default. */
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 */
Say '-------+'center('' ,cols*(w+1),'-')
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 */
Say center(idx,7)'¦' substr(dd,2) /* display partial list To the terminal.*/
idx= idx+cols /* bump idx by number of cols */
dd=''
End
End
End
If dd\=='' Then Say center(idx,7)'¦' substr(dd,2) /*possible display rest */
Say '--------'center('' ,cols*(w+1),'-')
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 ?
/*--------------------------------------------------------------------------------*/
tau: Procedure
Parse Arg x
If x<6 Then /* some low numbers are handled special */
Return 2+(x==4)-(x==1)
tau=0
odd=x//2
Do j=1 by 1 While j*j<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*/
tau=tau+2 /* bump n of divisors */
End
If j*j=x Then /* x is a square */
tau=tau+1 /* its root is a divisor */
Return tau
- output when using the default input:
index ¦ the first 100 tau numbers -------+---------------------------------------------------------------------- 1 ¦ 1 2 8 9 12 18 24 36 40 56 11 ¦ 60 72 80 84 88 96 104 108 128 132 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 ------------------------------------------------------------------------------
Ring
see "The first 100 tau numbers are:" + nl + nl
n = 1
num = 0
limit = 100
while num < limit
n = n + 1
tau = 0
for m = 1 to n
if n%m = 0
tau = tau + 1
ok
next
if n%tau = 0
num = num + 1
if num%10 = 1
see nl
ok
see "" + n + " "
ok
end
Output:
The first 100 tau 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
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
- Output:
{ 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 }
Ruby
require 'prime'
taus = Enumerator.new do |y|
(1..).each do |n|
num_divisors = n.prime_division.inject(1){|prod, n| prod *= n[1] + 1 }
y << n if n % num_divisors == 0
end
end
p taus.take(100)
- Output:
[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]
Rust
/// Gets all divisors of a number, including itself
fn get_divisors(n: u32) -> Vec<u32> {
let mut results = Vec::new();
for i in 1..(n / 2 + 1) {
if n % i == 0 {
results.push(i);
}
}
results.push(n);
results
}
fn is_tau_number(i: u32) -> bool {
0 == i % get_divisors(i).len() as u32
}
fn main() {
println!("\nFirst 100 Tau numbers:");
let mut counter: u32 = 0;
let mut i: u32 = 1;
while counter < 100 {
if is_tau_number(i) {
print!("{:>4}", i);
counter += 1;
print!("{}", if counter % 20 == 0 { "\n" } else { "," });
}
i += 1;
}
}
- Output:
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
Sidef
func is_tau_number(n) {
n % n.sigma0 == 0
}
say is_tau_number.first(100).join(' ')
- Output:
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
Swift
import Foundation
// See https://en.wikipedia.org/wiki/Divisor_function
func divisorCount(number: Int) -> Int {
var n = number
var total = 1
// Deal with powers of 2 first
while (n & 1) == 0 {
total += 1
n >>= 1
}
// Odd prime factors up to the square root
var p = 3
while p * p <= n {
var count = 1
while n % p == 0 {
count += 1
n /= p
}
total *= count
p += 2
}
// If n > 1 then it's prime
if n > 1 {
total *= 2
}
return total
}
let limit = 100
print("The first \(limit) tau numbers are:")
var count = 0
var n = 1
while count < limit {
if n % divisorCount(number: n) == 0 {
print(String(format: "%5d", n), terminator: "")
count += 1
if count % 10 == 0 {
print()
}
}
n += 1
}
- Output:
The first 100 tau 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
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
VTL-2
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
- Output:
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
Wren
import "./math" for Int
import "./fmt" for Fmt
System.print("The first 100 tau numbers are:")
var count = 0
var i = 1
while (count < 100) {
var tf = Int.divisors(i).count
if (i % tf == 0) {
Fmt.write("$,5d ", i)
count = count + 1
if (count % 10 == 0) System.print()
}
i = i + 1
}
- Output:
The first 100 tau 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 1,016 1,040 1,044 1,048 1,056 1,068 1,089 1,096
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;
];
]
- Output:
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
- Programming Tasks
- Prime Numbers
- Mathematics
- 11l
- Action!
- ALGOL 68
- ALGOL-M
- APL
- AppleScript
- Arturo
- Asymptote
- AutoHotkey
- AWK
- BASIC
- Applesoft BASIC
- BASIC256
- Chipmunk Basic
- Gambas
- GW-BASIC
- IS-BASIC
- Minimal BASIC
- MSX Basic
- QBasic
- Run BASIC
- True BASIC
- Tiny BASIC
- XBasic
- Yabasic
- BCPL
- C
- C++
- C sharp
- Clojure
- CLU
- Cowgol
- Craft Basic
- D
- Dart
- Delphi
- System.SysUtils
- Draco
- EasyLang
- F Sharp
- Factor
- Fermat
- Forth
- FreeBASIC
- Frink
- Go
- Haskell
- J
- Java
- Jq
- Julia
- Lua
- M2000 Interpreter
- MAD
- Mathematica
- Wolfram Language
- MiniScript
- Modula-2
- Nim
- Oberon-2
- PARI/GP
- Pascal
- Free Pascal
- PascalABC.NET
- Perl
- Ntheory
- Phix
- PILOT
- PL/M
- Prolog
- PureBasic
- Python
- Quackery
- R
- Racket
- Raku
- REXX
- Ring
- RPL
- Ruby
- Rust
- Sidef
- Swift
- Verilog
- VTL-2
- Wren
- Wren-math
- Wren-fmt
- XPL0