Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,6 +1,4 @@
import std.stdio, std.bigint;
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;
@ -10,7 +8,9 @@ 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]])
writefln("(%3d %3d) = %s", d[0], d[1], binomial(d[0], d[1]));
writeln("(100 50) = ", binomial(BigInt(100), BigInt(50)));
writeln("(100 50) = ", binomial(100.BigInt, 50.BigInt));
}

View file

@ -4,4 +4,5 @@ import "math/big"
func main() {
fmt.Println(new(big.Int).Binomial(5, 3))
fmt.Println(new(big.Int).Binomial(60, 30))
}

View file

@ -1,9 +1,3 @@
multi sub postfix:<!>(Int $a) {
[*] 1..$a;
}
sub infix:<choose>($n, $k) { ([*] $n-$k+1 .. $n) / [*] 2 .. $k }
sub binomialcoefficient($n, $k) {
$n! / (($n - $k)! * $k!);
}
say binomialcoefficient(5, 3);
say 5 choose 3;