Calculates the number of combinations of k items chosen from n items. If replacement is true, computes with replacement: (n + k - 1) choose k. If false, computes without replacement: n choose k.
k
n
replacement
Total number of items (n ≥ 0)
Number of items to choose (k ≥ 0)
Whether replacement is allowed (default: true)
The number of combinations
combinations(5, 3); // 35 (with replacement)combinations(5, 3, false); // 10 (no replacement) Copy
combinations(5, 3); // 35 (with replacement)combinations(5, 3, false); // 10 (no replacement)
Calculates the number of combinations of
k
items chosen fromn
items. Ifreplacement
is true, computes with replacement: (n + k - 1) choose k. If false, computes without replacement: n choose k.