Tau number: Difference between revisions

Added Prolog
(Added Prolog)
 
(13 intermediate revisions by 6 users not shown)
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}}==
Line 357 ⟶ 374:
 
=={{header|BASIC}}==
 
<syntaxhighlight lang="basic">10 DEFINT A-Z
20 S=0: N=1
Line 366 ⟶ 382:
70 IF S<100 THEN 30
80 END</syntaxhighlight>
 
{{out}}
 
<pre> 1 2 8 9 12
18 24 36 40 56
Line 390 ⟶ 404:
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}}===
Line 433 ⟶ 463:
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}}===
Line 451 ⟶ 516:
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}}===
Line 460 ⟶ 560:
130 NUM = 0
140 LIMIT = 100
150 IF NUM > LIMIT THEN GOTO 270230
160 N = N+1
170 TAU = 0
Line 530 ⟶ 630:
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}}===
Line 961 ⟶ 1,114:
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Dart}}==
{{trans|C++}}
<syntaxhighlight lang="dart">int divisorCount(int n) {
int total = 1;
// Deal with powers of 2 first
for (; (n & 1) == 0; n >>= 1) total++;
// Odd prime factors up to the square root
for (int p = 3; p * p <= n; p += 2) {
int count = 1;
for (; n % p == 0; n ~/= p) count++;
total *= count;
}
// If n > 1 then it's prime
if (n > 1) total *= 2;
return total;
}
 
void main() {
const int limit = 100;
print("The first $limit tau numbers are:");
int count = 0;
for (int n = 1; count < limit; n++) {
if (n % divisorCount(n) == 0) {
print(n.toString().padLeft(6));
count++;
}
}
}</syntaxhighlight>
 
=={{header|Delphi}}==
Line 1,056 ⟶ 1,238:
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func cntdiv n .
i = 1
while i <= sqrt n
if n mod i = 0
cnt += 1
if i <> n div i
cnt += 1
.
.
i += 1
.
return cnt
.
i = 1
while n < 100
if i mod cntdiv i = 0
write i & " "
n += 1
.
i += 1
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 1,887 ⟶ 2,094:
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>
 
Line 2,221 ⟶ 2,448:
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096</pre>
 
=={{header|Prolog}}==
{{works with|GNU Prolog}}
{{works with|SWI Prolog}}
<syntaxhighlight lang="prolog">tau(N, T) :-
findall(M, (between(1, N, M), 0 is N mod M), Ms),
length(Ms, T).
 
tau_numbers(Limit, Ns) :-
findall(N, (between(1, Limit, N), tau(N, T), 0 is N mod T), Ns).
 
print_tau_numbers :-
tau_numbers(1100, Ns),
writeln("The first 100 tau numbers are:"),
forall(member(N, Ns), format("~d ", [N])).
 
:- print_tau_numbers.</syntaxhighlight>
 
=={{header|PureBasic}}==
{{trans|FreeBasic}}<syntaxhighlight lang="purebasic">OpenConsole()
<syntaxhighlight lang="purebasic">OpenConsole()
 
Procedure.i numdiv(n)
Line 2,829 ⟶ 3,074:
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
 
=={{header|Tiny Craft Basic}}==
<syntaxhighlight lang="basic">10 let count = 0
20 let num = 0
30 let modulus = 0
40 let nums = 100
50 let tau = 0
 
60 rem do
 
70 let count = count + 1
80 let tau = 0
90 let modulus = 1
 
100 rem do
 
100 if count mod modulus <> 0 then 130
 
120 let tau = tau + 1
 
130 rem endif
 
140 let modulus = modulus + 1
 
150 if modulus < count + 1 then 100
 
160 if count mod tau <> 0 then 190
 
170 let num = num + 1
180 print count, tab,
 
190 rem endif
 
200 if num < nums then 60</syntaxhighlight>
 
=={{header|Verilog}}==
Line 2,928 ⟶ 3,139:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./fmt" for Fmt
 
System.print("The first 100 tau numbers are:")
2,122

edits