RosettaCodeData/Task/Factorial/D/factorial-3.d

17 lines
328 B
D
Raw Permalink Normal View History

2014-04-02 16:56:35 +00:00
import std.stdio, std.algorithm, std.range;
2015-02-20 00:35:01 -05:00
uint factorial(in uint n) pure nothrow @nogc
2014-04-02 16:56:35 +00:00
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;
}