maths.ncr_combinations¶
Generalized combinations (n choose r) calculator for real total and integer choose. Wikipedia URL: https://en.wikipedia.org/wiki/Binomial_coefficient
Attributes¶
Functions¶
|
Compute the number of combinations using the formula: |
Module Contents¶
- maths.ncr_combinations.combinations(total: float, choose: int) float¶
Compute the number of combinations using the formula:
combinations = total * (total-1) * … * (total-choose+1) / choose!
Parameters¶
- totalfloat
Total number of items. Can be any real number.
- chooseint
Number of items to select. Must be a non-negative integer.
Returns¶
- float
The number of combinations.
Raises¶
- ValueError
If choose is not a non-negative integer.
Examples¶
>>> combinations(5, 2) 10.0 >>> combinations(5.5, 2) 12.375 >>> combinations(10, 0) 1.0 >>> combinations(0, 0) 1.0 >>> combinations(5, -1) Traceback (most recent call last): ... ValueError: choose must be a non-negative integer >>> combinations(5, 2.5) Traceback (most recent call last): ... ValueError: choose must be a non-negative integer
- maths.ncr_combinations.total_input¶