Number.Combinations
NumberReturns the number of combinations for choosing k items from a set of n items, where order does not matter (C(n,k)).
Syntax
Number.Combinations(setSize as nullable number, combinationSize as nullable number) as nullable numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
setSize | number | Yes | The total number of items in the set (n). Must be a non-negative integer. |
combinationSize | number | Yes | The number of items to choose (k). Must be a non-negative integer <= setSize. |
Return Value
number — The number of unique combinations C(n,k) = n! / (k!(n-k)!).
Remarks
Number.Combinations computes the binomial coefficient C(n, k) — read as "n choose k". It returns the number of ways to select combinationSize items from a collection of setSize items when order does not matter. Two selections are considered identical if they contain the same elements regardless of the order chosen.
The formula is: C(n, k) = n! / (k! × (n − k)!)
Key properties:
- C(n, 0) = 1 — there is exactly one way to choose nothing
- C(n, n) = 1 — there is exactly one way to choose everything
- C(n, 1) = n — choosing 1 item gives n possibilities
- C(n, k) = C(n, n−k) — symmetry: choosing k is equivalent in count to leaving out k
When combinationSize > setSize, the result is 0 (impossible selection). Results can grow extremely large for large inputs — C(100, 50) exceeds 10^29, which exceeds double-precision integer precision.
For ordered selections (where order matters), use Number.Permutations instead. Number.Permutations(n, k) = Number.Combinations(n, k) × k!.
Examples
Example 1: How many 2-item subsets can be chosen from 5 items?
Number.Combinations(5, 2)Result | |
|---|---|
| 1 | 10 |
Example 2: Lottery probability — how many ways to choose 6 numbers from 49?
Number.Combinations(49, 6)Result | |
|---|---|
| 1 | 13,983,816 |
Example 3: Edge cases and symmetry property of combinations
#table(
{"k", "C(5,k)"},
{
{0, Number.Combinations(5, 0)},
{1, Number.Combinations(5, 1)},
{2, Number.Combinations(5, 2)},
{3, Number.Combinations(5, 3)},
{4, Number.Combinations(5, 4)},
{5, Number.Combinations(5, 5)}
}
)k | C(5,k) | |
|---|---|---|
| 1 | 0 | 1 |
| 2 | 1 | 5 |
| 3 | 2 | 10 |
| 4 | 3 | 10 |
| 5 | 4 | 5 |
| 6 | 5 | 1 |