Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Factorial/D/factorial-1.d
Normal file
19
Task/Factorial/D/factorial-1.d
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
uint factorial(in uint n) pure nothrow @nogc
|
||||
in {
|
||||
assert(n <= 12);
|
||||
} body {
|
||||
uint result = 1;
|
||||
foreach (immutable i; 1 .. n + 1)
|
||||
result *= i;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Computed and printed at compile-time.
|
||||
pragma(msg, 12.factorial);
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
|
||||
// Computed and printed at run-time.
|
||||
12.factorial.writeln;
|
||||
}
|
||||
19
Task/Factorial/D/factorial-2.d
Normal file
19
Task/Factorial/D/factorial-2.d
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
uint factorial(in uint n) pure nothrow @nogc
|
||||
in {
|
||||
assert(n <= 12);
|
||||
} body {
|
||||
if (n == 0)
|
||||
return 1;
|
||||
else
|
||||
return n * factorial(n - 1);
|
||||
}
|
||||
|
||||
// Computed and printed at compile-time.
|
||||
pragma(msg, 12.factorial);
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
|
||||
// Computed and printed at run-time.
|
||||
12.factorial.writeln;
|
||||
}
|
||||
16
Task/Factorial/D/factorial-3.d
Normal file
16
Task/Factorial/D/factorial-3.d
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import std.stdio, std.algorithm, std.range;
|
||||
|
||||
uint factorial(in uint n) pure nothrow @nogc
|
||||
in {
|
||||
assert(n <= 12);
|
||||
} body {
|
||||
return reduce!q{a * b}(1u, iota(1, n + 1));
|
||||
}
|
||||
|
||||
// Computed and printed at compile-time.
|
||||
pragma(msg, 12.factorial);
|
||||
|
||||
void main() {
|
||||
// Computed and printed at run-time.
|
||||
12.factorial.writeln;
|
||||
}
|
||||
22
Task/Factorial/D/factorial-4.d
Normal file
22
Task/Factorial/D/factorial-4.d
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
uint factorial(in uint n) pure nothrow
|
||||
in {
|
||||
assert(n <= 12);
|
||||
} body {
|
||||
static uint inner(uint n, uint acc) pure nothrow @nogc {
|
||||
if (n < 1)
|
||||
return acc;
|
||||
else
|
||||
return inner(n - 1, acc * n);
|
||||
}
|
||||
return inner(n, 1);
|
||||
}
|
||||
|
||||
// Computed and printed at compile-time.
|
||||
pragma(msg, 12.factorial);
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
|
||||
// Computed and printed at run-time.
|
||||
12.factorial.writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue