Skip to main content

geop_core_math/
combinatorics.rs

1//! Counting, exactly in integers.
2
3/// `n` choose `k`, exactly, for the small `n` of a polynomial's degree:
4/// each partial product is itself a binomial coefficient, so every division
5/// is exact.
6pub fn binomial(n: usize, k: usize) -> i64 {
7    (0..k).fold(1i64, |acc, i| acc * (n - i) as i64 / (i as i64 + 1))
8}