/*
This program computes the total number of lottery combinations for:
- choosing 6 numbers out of 37
- choosing 1 power number out of 7
Total combinations = C(37,6) * C(7,1)
We implement an idiomatic binomial coefficient function using the
multiplicative formula:
C(n, k) = product(i = 1..k) of (n - k + i) / i
Why this method?
- Avoids huge factorials (37! is far too large for u64)
- Keeps intermediate values small and exact
- Efficient, clean, and idiomatic Rust
*/
fn binomial_coefficient(n: u64, k: u64) -> u64 {
if k > n {
return 0;
}
// Use symmetry: C(n, k) == C(n, n-k)
let mut k = k;
if k > n - k {
k = n - k;
}
let mut result: u64 = 1;
for i in 1..=k {
result = result * (n - k + i) / i;
}
result
}
fn main() {
let main_n: u64 = 37;
let main_k: u64 = 6;
let power_n: u64 = 7;
let power_k: u64 = 1;
let main_combos: u64 = binomial_coefficient(main_n, main_k);
let power_combos: u64 = binomial_coefficient(power_n, power_k);
let total: u64 = main_combos * power_combos;
println!("Main combinations (C(37,6)): {}", main_combos);
println!("Power combinations (C(7,1)): {}", power_combos);
println!("Total lottery combinations: {}", total);
}
/*
run:
Main combinations (C(37,6)): 2324784
Power combinations (C(7,1)): 7
Total lottery combinations: 16273488
*/