Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,8 +1,8 @@
T binomial(T)(in T n, T k) pure /*nothrow*/ {
T binomial(T)(in T n, T k) pure nothrow {
if (k > (n / 2))
k = n - k;
T bc = 1;
foreach (T i; cast(T)2 .. k + 1)
foreach (T i; T(2) .. k + 1)
bc = (bc * (n - k + i)) / i;
return bc;
}
@ -10,7 +10,7 @@ T binomial(T)(in T n, T k) pure /*nothrow*/ {
void main() {
import std.stdio, std.bigint;
foreach (d; [[5, 3], [100, 2], [100, 98]])
foreach (const d; [[5, 3], [100, 2], [100, 98]])
writefln("(%3d %3d) = %s", d[0], d[1], binomial(d[0], d[1]));
writeln("(100 50) = ", binomial(100.BigInt, 50.BigInt));
}