Method and source check
Last checked:
Automated source and implementation review, including worked examples and documented numerical limits. This review does not provide professional advice or specialist approval.
Method
For nonnegative integers 0≤k≤n, compute combinations with a multiplicative BigInt formula and permutations with a falling product.
C(n,k) = n!/(k!(n−k)!)
P(n,k) = n!/(n−k)!
Variables and units
- n
- number of distinct available items
- k
- number selected, 0≤k≤n
Worked example
For n=5,k=2, combinations are 10 and permutations are 20.
Limitations
Valid integer results are returned as exact decimal strings; there is no rounding.
- Assumes distinct items selected without replacement.
- Inputs must fit the validated JavaScript integer range; very large calculations may take time.
- C(n,0)=C(n,n)=1.
- P(n,k)=C(n,k)×k!.