Skip to content
BytePatterns

Permutations vs Combinations

Math & Number Theory: lesson 5 of 5

Divide by k! the moment order stops mattering.

Lesson 5 of 5 · 5 min

Permutations vs Combinations

Step 1 of 7

Five runners, three podium places. Gold has five candidates, silver four, bronze three.

The Idea

Three podium places, five runners: five choices, then four, then three. That is 60 ordered line-ups — a permutation, n! / (n - k)!.

If only the group matters, each trio has been counted 3! times, once per ordering. Divide that away and 60 becomes 10. Pascal's triangle stores the same counts: every entry is the two above it, because the newest runner is either in or out.

Real-World Example

A/B testing asks combinations: how many pairs of variants can be compared. Scheduling asks permutations: how many orders the same tasks could run in. Reaching for the wrong one is why an estimate comes back six times too large.

The Code

from math import comb, factorial, perm

print(perm(5, 3))                    # 60  -> ordered podiums
print(factorial(5) // factorial(2))  # 60  -> the same n! / (n-k)!
print(comb(5, 3))                    # 10  -> order thrown away
print(perm(5, 3) // factorial(3))    # 10  -> divided by k! by hand
print(comb(5, 3) == comb(5, 2))      # True -> pick who is left out instead

Python

Your turn

Fill in the blank.

# turn ordered picks into unordered groups
combinations = perm(n, k) // ___

Mini quiz

1 / 3

How many ordered podiums can three of five runners fill?

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.