Add binomial to math

This commit is contained in:
Fabian Schmidt 2024-11-18 11:40:44 +01:00
parent fdf46c9dd3
commit 49b0f24c1b

View File

@ -49,6 +49,14 @@ pub fn factorial(n: u64) -> u64 {
result result
} }
pub fn binomial(n: u64, k: u64) -> u64 {
if k > n {
0
} else {
factorial(n) / (factorial(k) * factorial(n - k))
}
}
pub fn get_divisors(n: u64) -> Vec<u64> { pub fn get_divisors(n: u64) -> Vec<u64> {
let mut divisors = HashSet::from([1]); let mut divisors = HashSet::from([1]);
let mut potential_divisor = 2; let mut potential_divisor = 2;