Understanding the permutation and combination calculator — concept and principle
Permutations and combinations count the ways to choose r items from n distinct items. A permutation (nPr) cares about order, like awarding gold, silver and bronze medals; a combination (nCr) ignores order, like choosing a committee or lottery numbers. This calculator gives both, plus the two "with repetition" versions, so you can match the count to the situation.
How it is calculated
- Permutations: nPr = n! ÷ (n − r)! = n × (n − 1) × … × (n − r + 1).
- Combinations: nCr = n! ÷ (r! (n − r)!) = nPr ÷ r!.
- Ordered, repetition allowed: nʳ (each of r positions can be any of n items).
- Unordered, repetition allowed: (n + r − 1)Cr, also written nHr.
n and r are whole numbers with 0 ≤ r ≤ n for the first two formulas.
The principle
For an ordered choice there are n options for the first pick, n − 1 for the second, and so on for r picks; multiplying them gives nPr. Each unordered group of r items appears in that list r! times, once for each of its possible orders, so dividing by r! leaves the number of combinations. With repetition, every pick has all n options, giving nʳ. Unordered selection with repetition is counted by the "stars and bars" idea: choosing r items from n types is the same as placing r stars and n − 1 dividing bars in a row, which can be done in (n + r − 1)Cr ways.
Worked example
- Inputs: n = 10, r = 3.
- nPr = 10 × 9 × 8 = 720.
- nCr = 720 ÷ 3! = 720 ÷ 6 = 120.
- With repetition, ordered: 10³ = 1,000 (all three-digit codes from 000 to 999).
- With repetition, unordered: (10 + 3 − 1)C3 = 12C3 = 12 × 11 × 10 ÷ 6 = 220.
How to read the result
Ask two questions: does order matter, and can an item be used more than once? The answers point to one of the four results. Combination counts are symmetric, nCr = nC(n − r), so choosing 3 of 10 to include gives the same count as choosing 7 to leave out. The probability of one particular combination is 1 ÷ nCr; for a 6-from-45 lottery that is 1 in 8,145,060.
Common mistakes
- Using permutations for a committee or a lottery ticket, where order does not matter.
- Forgetting to divide by r! and overcounting by a factor of r!.
- Applying formulas for distinct items to groups with identical items (letters of "BOOK", for example), which need division by the factorials of the repeats.
- Using nʳ when items cannot be reused, or nPr when they can.
Frequently asked questions
What is the difference between nPr and nCr in one sentence?
nPr counts ordered selections, nCr counts unordered ones, and nPr = nCr × r!.
What is nC0 or nCn?
Both equal 1: there is exactly one way to choose nothing and one way to choose everything.
How many 5-card poker hands are there?
A hand is unordered, so it is 52C5 = 2,598,960.
Sources: Donald E. Knuth, The Art of Computer Programming, Vol. 1, §1.2.6 (Binomial Coefficients) · R. L. Graham, D. E. Knuth and O. Patashnik, Concrete Mathematics, 2nd ed., Addison-Wesley, 1994, Chapter 5