use crate::prelude::*;
pub fn h_permutations<T, S>(total: &T, select: &S) -> u64
where
T: Copy + Into<u64>,
S: Copy + Into<u64>,
{
let n: u64 = (*total).into();
let r: u64 = (*select).into();
return n.h_factorial() / (n - r).h_factorial();
}
pub fn h_combinations<T, S>(total: &T, select: &S) -> u64
where
T: Copy + Into<u64>,
S: Copy + Into<u64>,
{
let n: u64 = (*total).into();
let r: u64 = (*select).into();
return n.h_factorial() / (r.h_factorial() * (n - r).h_factorial());
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_h_permutations() {
assert_eq!(h_permutations(&5u32, &2u64), 20);
assert_eq!(h_permutations(&4u64, &2u32), 12);
}
#[test]
fn test_h_combinations() {
assert_eq!(h_combinations(&5u32, &2u32), 10);
assert_eq!(h_combinations(&4u64, &2u64), 6);
}
}