combinations

combinations(n, k)

Try it yourself:


combinations(): choose distinct items

combinations(n, k) counts ways to choose k items from n distinct items when order does not matter and no item can be chosen twice. combinations(5, 2) is 10: five objects produce ten unordered pairs.

Formula

The calculation is the binomial coefficient, n!/(k!(n-k)!). It differs from permutations: choosing A then B is the same selection as B then A. Use permutations() when arrangement order matters.

Applications

Combinations model committees, card hands, sample selection, and branching choices. factorial() explains the formula, while combinationsWithRep() covers selections that allow repeats. For probabilities, combine the count with division.

Limits

n and k should be non-negative integers with k no larger than n. Large values grow rapidly, so retain exact values where possible and avoid converting to floating point prematurely.

Try Combinations in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions