Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
18
Task/Left-factorials/D/left-factorials.d
Normal file
18
Task/Left-factorials/D/left-factorials.d
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import std.stdio, std.bigint, std.range, std.algorithm, std.conv;
|
||||
|
||||
BigInt leftFact(in uint n) pure nothrow /*@safe*/ {
|
||||
BigInt result = 0, factorial = 1;
|
||||
foreach (immutable i; 1 .. n + 1) {
|
||||
result += factorial;
|
||||
factorial *= i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void main() {
|
||||
writeln("First 11 left factorials:\n", 11.iota.map!leftFact);
|
||||
writefln("\n20 through 110 (inclusive) by tens:\n%(%s\n%)",
|
||||
iota(20, 111, 10).map!leftFact);
|
||||
writefln("\nDigits in 1,000 through 10,000 by thousands:\n%s",
|
||||
iota(1_000, 10_001, 1_000).map!(i => i.leftFact.text.length));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue