Tau function: Difference between revisions

Added Asymptote
(Add Scala implementation)
(Added Asymptote)
 
(2 intermediate revisions by 2 users not shown)
Line 490:
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</pre>
 
=={{header|Asymptote}}==
<syntaxhighlight lang="Asymptote">write("The tau functions for the first 100 positive integers are:");
for (int N = 1; N <= 100; ++N) {
int T;
if (N < 3) {
T = N;
} else {
T = 2;
for (int A = 2; A <= (N + 1) / 2; ++A) {
if (N % A == 0) T = T + 1;
}
}
write(format("%3d", T), suffix=none);
if (N % 10 == 0) write("");
}</syntaxhighlight>
 
=={{header|AutoHotkey}}==
Line 1,160 ⟶ 1,176:
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</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("Count of divisors for the first $limit positive integers:");
for (int n = 1; n <= limit; ++n) {
print(divisorCount(n).toString().padLeft(3));
}
}</syntaxhighlight>
 
=={{header|Delphi}}==
Line 2,829 ⟶ 2,870:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./fmt" for Fmt
 
System.print("The tau functions for the first 100 positive integers are:")
2,122

edits