RosettaCodeData/Task/Multifactorial/D/multifactorial.d

13 lines
336 B
D
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
import std.stdio, std.algorithm, std.range;
2014-01-17 05:32:22 +00:00
T multifactorial(T=long)(in int n, in int m) pure /*nothrow*/ {
2013-04-10 21:29:02 -07:00
T one = 1;
return reduce!q{a * b}(one, iota(n, 0, -m));
}
void main() {
2014-01-17 05:32:22 +00:00
foreach (immutable m; 1 .. 11)
2013-04-10 21:29:02 -07:00
writefln("%2d: %s", m, iota(1, 11)
2014-01-17 05:32:22 +00:00
.map!(n => multifactorial(n, m)));
2013-04-10 21:29:02 -07:00
}