RosettaCodeData/Task/Evaluate-binomial-coefficients/Seed7/evaluate-binomial-coefficients-2.seed7
2023-07-01 13:44:08 -04:00

26 lines
627 B
Text

const func bigInteger: (in bigInteger: n) ! (in var bigInteger: k) is func
result
var bigInteger: binom is 0_;
local
var bigInteger: numerator is 0_;
var bigInteger: denominator is 0_;
begin
if n >= 0_ and k > n >> 1 then
k := n - k;
end if;
if k < 0_ then
binom := 0_;
elsif k = 0_ then
binom := 1_;
else
binom := n;
numerator := pred(n);
denominator := 2_;
while denominator <= k do
binom *:= numerator;
binom := binom div denominator;
decr(numerator);
incr(denominator);
end while;
end if;
end func;