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.