/*
This program computes the total number of Powerball lottery combinations:
- Choose 5 distinct numbers out of 69
- Choose 1 Powerball number out of 26
Total combinations = C(69, 5) * 26
It uses:
- bigint for safe integer arithmetic
- an efficient binomial coefficient function
- Intl.NumberFormat for comma formatting
*/
/*
binomial(n, k):
Computes C(n, k) using the multiplicative formula:
C(n, k) = Π (n - i + 1) / i for i = 1..k
Implemented using bigint to avoid overflow.
*/
function binomial(n: number, k: number): bigint {
if (k > n) return 0n;
if (k > n - k) k = n - k; // symmetry: C(n, k) = C(n, n-k)
let result: bigint = 1n;
for (let i: number = 1; i <= k; i++) {
result = result * BigInt(n - i + 1) / BigInt(i);
}
return result;
}
/*
formatWithCommas(value):
Formats a bigint with commas.
*/
function formatWithCommas(value: bigint): string {
return new Intl.NumberFormat("en-US").format(Number(value));
}
/*
Main
*/
const MAIN_COUNT: number = 5;
const MAIN_MAX: number = 69;
const POWER_MAX: number = 26;
// Compute C(69, 5)
const mainCombinations: bigint = binomial(MAIN_MAX, MAIN_COUNT);
// Multiply by 26 Powerball choices
const totalCombinations: bigint = mainCombinations * BigInt(POWER_MAX);
// Output results
console.log("Powerball combinations (5 out of 69 and 1 out of 26):");
console.log("C(69, 5) =", formatWithCommas(mainCombinations));
console.log("Total combinations =", formatWithCommas(totalCombinations));
/*
run:
Powerball combinations (5 out of 69 and 1 out of 26):
C(69, 5) = 11,238,513
Total combinations = 292,201,338
*/