Statistics Permutations
A permutation counts the number of ways to arrange items when the order in which they are placed matters.
What Is a Permutation?
A permutation is an arrangement of items where order matters. Picking a gold, silver, and bronze medalist from a race is a permutation problem, because swapping who gets gold and who gets silver produces a genuinely different outcome, even with the same three runners on the podium.
The Permutation Formula
The number of ways to arrange r items out of n available items, when order matters, is P(n, r) = n! / (n − r)!. Here n! (n factorial) is n × (n − 1) × (n − 2) × … × 1. The formula works by counting down the choices available for each position: n choices for the first slot, n − 1 for the second, and so on for r slots.
Example: Awarding 3 Medals Among 6 Runners
import math
n = 6 # runners in the race
r = 3 # medal positions: gold, silver, bronze
permutations = math.perm(n, r)
manual = math.factorial(n) // math.factorial(n - r)
print(f"P(6,3) = {permutations}") # 120
print(f"Manual check: {manual}") # 120- Order matters — ABC and BAC count as two different permutations.
- Each item is used at most once per arrangement (no repetition unless stated otherwise).
- Written as P(n, r) or nPr, read as 'n permute r'.
- When r = n, every item is placed, so P(n, n) simplifies to n!.
Permutations of All n Items
When you arrange every item in a set (r = n), the count of full arrangements is simply n!. For example, the number of ways to line up all 5 books on a shelf, using every book, is 5! = 120 — every one of those arrangements uses all 5 books, just in a different order.
Full Arrangements and a Range of r Values
import math
books = 5
full_arrangements = math.factorial(books)
print(f"Ways to arrange all {books} books: {full_arrangements}") # 120
for r in range(1, books + 1):
print(f"P({books},{r}) = {math.perm(books, r)}")Permutations show up anywhere sequence matters: ranking finishers in a competition, assigning people to numbered seats, scheduling tasks in order, or generating passwords where the digit sequence itself is the point.