Contents
Deep Breakdown
What it tells me (Situation Awareness): counts the number of ways to select objects from distinct objects AND arrange them in order. Order matters here: selecting items A, B is different from B, A. Used in ranking problems, slot-filling sequences, and anywhere position matters.
Flowchart
Real-world use
Where it is used
Ranking top-k items from a list: top-3 email subject lines to test sequentially, finalist rankings in a competition, or multi-step recommendation slot filling.
Problem it solves
How many distinct ordered sequences of items can I form from choices, without repeating an item?
How it solves the problem
By the multiplication principle: first position has choices, second has , ..., -th has . The product telescopes to .
Example in a business
Testing which 3 of 10 landing page variants to show in order to different user segments: ordered sequences. Used to assess whether exhaustive testing is feasible.
The formula, piece by piece
- : pool size (total distinct objects).
- : number to select and arrange.
- : total ways to order all objects.
- : divide out the orderings of the unused objects.
The formula in words
"The number of ordered arrangements of objects chosen from distinct objects equals factorial divided by factorial."
Critical Concepts
- (all objects, ordered = full factorial).
- (pick 1 object, choices).
- Contrast with combinations: — dividing by removes the ordering.
- Python:
math.perm(n, r)(3.8+) ormath.factorial(n)/math.factorial(n-r).
Step-by-step calculation (tiny example)
Step 1: Identify n=4, r=2 4 distinct colors, pick 2 to paint the top and bottom of a flag (order matters).
Step 2: Apply formula
Step 3: Verify by enumeration Top choices: {R,G,B,Y}. For each top choice, 3 remaining for bottom: . Confirmed.
Code examples
Beginner example (Python)
import math # How many ways to assign top-3 ranks from 8 finalists?
n_finalists = 8
r_ranks = 3
ordered_arrangements = math.perm(n_finalists, r_ranks)
print(f"P({n_finalists}, {r_ranks}) = {ordered_arrangements}") # 336Beginner example (R)
# P(n, r) in R
n_finalists <- 8
r_ranks <- 3
ordered_arrangements <- factorial(n_finalists) / factorial(n_finalists - r_ranks)
cat("P(", n_finalists, ",", r_ranks, ") =", ordered_arrangements, "\n") # 336Professional example (Python)
import math
import itertools
def count_ordered_arrangements(pool_size: int, selection_size: int) -> int:
"""Count ordered selections of selection_size from pool_size distinct items. Args: pool_size: n, total distinct items. selection_size: r, items to select and order. Returns: P(n, r) = n! / (n - r)! Raises: ValueError: if selection_size > pool_size. """
if selection_size > pool_size:
raise ValueError(f"r={selection_size} cannot exceed n={pool_size}")
return math.perm(pool_size, selection_size) # Campaign slot-filling feasibility check
SLOT_SIZES = [2, 3, 4, 5]
POOL_SIZE = 10
print(f"Pool size: {POOL_SIZE} campaigns")
print(f"{'Slots (r)':>10} {'P(10,r)':>12} {'Feasible (< 1M)?':>18}")
for r_slots in SLOT_SIZES:
arrangements = count_ordered_arrangements(POOL_SIZE, r_slots)
feasible = arrangements < 1_000_000
print(f"{r_slots:>10} {arrangements:>12,} {str(feasible):>18}")Source: AIO p. 60