01
Choose (no repeat)
Formula: C(n,k) = n! / (k!(n − k)!)
Worked example: Choose 3 of 10 people. Since order does not matter, C(10,3) = 120 committees.
Open this example: committee chooseInteractive Math & Science Lessons
Counting Theory — Case by Case
01
Formula: C(n,k) = n! / (k!(n − k)!)
Worked example: Choose 3 of 10 people. Since order does not matter, C(10,3) = 120 committees.
Open this example: committee choose02
Formula: P(n,k) = n! / (n − k)!
Worked example: Award gold, silver, and bronze among 10 finalists. Since the roles differ, P(10,3) = 720 podiums.
Open this example: podium order03
Formula: nk
Worked example: Create a 4-digit PIN from 10 digits. Order matters and digits may repeat, so 10^4 = 10,000 PINs.
Open this example: pin code04
Formula: C(n + k − 1, k)
Worked example: Choose 3 scoops from 8 flavors, ignoring scoop order and allowing repeats. C(10,3) = 120 flavor multisets.
Open this example: ice-cream scoops05
Formula: N! / (n1! · n2! · … · nr!)
Worked example: MISSISSIPPI has 11 letters with I×4, S×4, P×2, and M×1. Dividing duplicate swaps gives 11!/(4!4!2!) = 34,650 arrangements.
Open this example: MISSISSIPPI06
Formula: Σi=0m (−1)iC(m,i)(m − i)n
Worked example: Assign 6 distinct tasks to 3 named workers, with nobody empty. Inclusion–exclusion gives 3^6 − 3·2^6 + 3 = 540 assignments.
Open this example: distinct to bins (onto)07
Formula: C(n,k) − C(b,k)
Worked example: Choose an unordered 5-card hand containing at least one Ace. C(52,5) − C(48,5) = 886,656 hands.
Open this example: at least one Ace08
Formula: !n = n! Σi=0n (−1)i / i!
Worked example: Assign 8 Secret Santa names with no self-draws. The derangement count !8 = 14,833 valid assignments.
Open this example: secret santaPractice
Predict the answer first, then use the controls above to find out. Reveal only after you have committed to a guess — that is what makes it practice.
Pick 3 people from 10 for a committee. Then pick 1st, 2nd and 3rd place from the same 10. Same n, same k — do the two counts differ, and if so by exactly what factor? Check with the first two models.
A 4-digit PIN drawn from 10 digits, and 4 ice-cream scoops chosen from 10 flavours where a flavour may repeat. Both allow repetition. Predict which count is larger, then check.
nk = 104. The scoops are unordered with repetition, C(n + k − 1, k) = C(13,4) = 715. The two "with repeats" models sit as far apart as the two "without" ones, which is why "can things repeat?" is never a sufficient question on its own. You always need both.Six distinct prizes into three distinct boxes gives 729. Switch the variant so every box must receive at least one prize and it falls to 540. Where did the missing 189 arrangements go?
Choosing 3 from 10 gives 120 ways. Derive it from the ordered count, and then find why 120 is also the answer to choosing 7.
Count ordered selections first, because they are easier: ten choices, then nine, then eight.
That counts each set of three several times over — once for every order the same three could arrive in, which is 3! = 6.
Dividing gives 120, and the division by k! is the entire difference between a permutation and a combination.
The symmetry follows from what choosing means. Picking 3 to take is the same act as picking 7 to leave, so the two counts cannot differ.
The panel's log₁₀ of 2.0792 is the practical companion: three digits. For large n the count overflows anything you can hold, and the logarithm is what remains computable.
Answer
The tool prints 120, 3 digits and log₁₀ = 2.0792. The symmetry is worth internalising because it halves the work: nobody should compute C(10, 7) from scratch. And the whole row sums to 2¹⁰ = 1024 — every subset of ten items, counted by size — which is the fastest sanity check on any binomial calculation you will ever run. The largest entry is C(10, 5) = 252, so the middle of the row holds about a quarter of all subsets while the two extremes hold one each.
A five-card hand can be dealt 2,598,960 ways. Build that from the ordered deal, then use it to price a flush. This is Choose (no repeat) with n = 52 and k = 5.
Deal in order first. The first card has 52 possibilities, the next 51, and so on down to 48 — five factors, no division yet.
A hand is a set, and the ordered count has recorded every set 120 times, once per order the same five cards could have arrived in. Dividing by 5! is the only step that turns a deal into a hand.
Now count the flushes inside that space: choose the suit four ways, then five of the thirteen cards in it.
Which settles what makes a flush rare. It is not that 5,148 is a small number of hands — it is that the space it sits inside is five hundred times larger.
And that space is still small enough to be physical. One hand every second, without stopping, and every distinct hand has been dealt inside a month.
Answer
The tool prints 2,598,960, 7 digits and log₁₀ = 6.4148. Poker's hand ranking is this arithmetic and nothing else. Count the straights the same way — ten starting ranks, four suits for each of five cards, 10 × 4⁵ = 10,240 — and there are twice as many straights as flushes, which is exactly why a flush outranks a straight. The ordering was not designed; it was counted.
An eight-letter password with no repeated letter has 62,990,928,000 forms. Count it, then count the same password without the rule, and decide which one you would rather be defending. This is Arrange (no repeat) with n = 26 and k = 8.
Fill the slots left to right. The first takes any of 26 letters; the second takes 25, because the letter you spent is gone.
Eight descending factors, and that product is the whole answer. It is a permutation rather than a combination because the order of the letters is the password.
Now delete the rule. Every slot is independent again and every slot has all 26 letters, so the count is a plain power.
The comparison is the point: forbidding repeats keeps 30.2% of the strings. A rule that sounds like a strengthening has removed seven strings in ten.
In attacker time, at a billion guesses a second, the two spaces are one minute and three and a half minutes. Neither is a defence — and the rule made the shorter one shorter.
Answer
With n = 26, k = 8 and the model set to Arrange (no repeat), the tool prints 62,990,928,000, 11 digits and log₁₀ = 10.7993. Every composition rule shrinks the space, without exception, because a rule can only forbid. Whether it earns its place depends on something this arithmetic cannot see: whether the strings it forbids are ones people choose far more often than chance. Banning one notorious password costs one string. Banning all repeated letters costs 145,836,136,576 of them.
A four-digit PIN has 10,000 values. Work out what three attempts at a cash machine are worth, and what the familiar advice to avoid repeated digits actually costs. This is Ordered with repeat with n = 10 and k = 4.
Four slots, ten digits in each, and nothing connects them — the digit you just used is still available for the next slot.
Three attempts against a PIN chosen uniformly is therefore three chances in ten thousand. The three-try limit is not an improvement on unlimited guessing; against this space it is the entire defence.
Now impose the no-repeated-digit rule: ten choices, then nine, then eight, then seven.
The rule keeps 5,040 PINs and destroys 4,960. Half the space is gone — and the half that went included 1111 along with everything else.
Two extra digits is not two extra guesses. Each digit multiplies by ten, so a six-digit PIN is a hundred times the space.
Answer
The tool prints 10,000 for n = 10, k = 4. Both facts hold at once: the space is tiny, and a PIN is usually fine anyway — because the three-attempt limit hands an attacker 0.03% of it rather than all of it. Change the threat and the answer inverts. A stolen file of PINs has no attempt limit, and ten thousand candidates is a fraction of a second's work, which is why the security of a PIN never rests on the PIN.
Three scoops from eight flavours, repeats allowed, is 120 — the same number as choosing three people from ten. Show that this is not a coincidence. This is Choose with repeat with n = 8 and k = 3.
Write the order as a row of symbols: a star for each scoop, a bar for each step up to the next flavour. Three scoops among eight flavours need three stars and seven bars.
Every arrangement of those ten symbols is one order, and every order is one arrangement. So the question is only which 3 of the 10 positions hold stars — which is problem 1's question with different nouns.
Forbid the repeats and the count falls to 56. Permission to repeat a flavour is worth 64 extra orders, more than doubling the menu.
Now let order matter as well, so that vanilla-vanilla-mint differs from mint-vanilla-vanilla: eight independent choices, three times over.
The ratio between those two is 4.27, not 3! = 6. A cone with a repeated scoop has fewer distinct orderings than one with three different scoops, so dividing by 3! is exactly the step you may not take here.
Answer
The tool prints 120, 3 digits and log₁₀ = 2.0792 — the same readout as problem 1, from a different question. Stars and bars is a translation rather than a formula: it turns repetition into position, where you already know what to do. The trap it sets is step 5. Once repeats are allowed the orderings stop being interchangeable, and no single factor converts between the ordered and the unordered count.
The letters of MISSISSIPPI make 34,650 distinct words. Derive it, then answer a harder question the tool has no field for: how often do the four S's avoid each other? This is Multiset permutation with counts 1, 4, 4, 2.
Start by pretending every letter is distinguishable — label the S's S₁ to S₄. Then it is a plain permutation of eleven objects.
Now remove the labels. The four S's can be permuted 4! ways without changing what is written, and the same goes for the four I's and the two P's, so every visible word was counted 1,152 times.
Which gives a probability directly: shuffle the eleven tiles and one arrangement in 34,650 spells the state's name.
For the harder question, seat the other seven letters first — M, four I's, two P's — and count their arrangements. That leaves eight gaps including the two ends, and each S must take a different gap.
Multiply and divide: 7,350 of the 34,650 words keep the S's apart, which is 21.2%.
Answer
The tool prints 34,650, 5 digits and log₁₀ = 4.5397. The gap method in steps 4 and 5 is worth more than the answer. It is the general move for any no two of these together condition: place the unconstrained items, then choose gaps for the constrained ones. Adjacency is a condition no factorial can express, and the gaps convert it into a choice of positions — which is the one thing every formula on this page already knows how to count.
Six distinct tasks handed to three workers with nobody left idle is 540 assignments. Derive it by removing the bad cases rather than counting the good ones. This is Balls into bins, distinct objects, every bin used, with n = 6 and m = 3.
Ignore the requirement first. Each task independently picks one of three workers, so the unrestricted count is a power — and it is far easier than the restricted one.
Now subtract the assignments that leave someone with nothing: choose the idle worker three ways, then give all six tasks to the other two.
That subtraction went too far. An assignment using only one worker was subtracted twice, once for each colleague it left idle, so those three come back.
Alternating subtraction and addition is inclusion–exclusion, and the alternating sum is what the tool's formula line shows.
So three quarters of all assignments happen to use everybody. Divide by 3! to make the workers interchangeable and you get S(6, 3) = 90, the Stirling number of the second kind — the same partitions, counted without names.
Answer
The tool prints 540, 3 digits and log₁₀ = 2.7324. Step 3 is where this problem is usually lost. The instinct is that subtracting the bad cases is the method, and it is not: subtraction over overlapping sets always overshoots, and the correction terms are not decoration. The 90 in step 5 is the same object from another angle — with named workers there are 540 assignments, without names 90 partitions, and the gap between them is exactly the 3! ways of handing out the names.
Twelve identical tokens into four labelled boxes with none empty is 165. Get there by paying the constraint up front. This is Balls into bins, identical objects, no bin empty, with n = 12 and m = 4.
The requirement is that every box gets at least one, so satisfy it immediately: drop one token in each box and stop thinking about it. Eight tokens are left, and now there are no rules at all.
Distributing identical items freely is stars and bars — eight stars, three bars to separate four boxes — and the count is the choice of which positions the bars take.
Drop the non-empty rule and the same method gives 455, because all twelve tokens are free.
So the floor of one costs nearly two thirds of the distributions: 165 of the 455 survive it.
Make the tokens distinguishable instead and the count jumps to 16,777,216. Identity is expensive — five orders of magnitude, for twelve objects.
Answer
The tool prints 165, 3 digits and log₁₀ = 2.2175. Step 1 is the transferable move: a lower bound on every part can be paid in advance, because paying it leaves a problem of the same shape with a smaller n. Raise the floor to three each and it leaves twelve minus twelve, so the answer is one. It does not work upwards, and that asymmetry is the whole reason at most two per box is a harder question than at least one.
886,656 five-card hands contain at least one ace. Count the hands that do not and subtract — then rebuild the same number the long way as a check. This is Inclusion-Exclusion, at-least-one, with n = 52, k = 5 and 48 cards that are not aces.
Counting hands with at least one ace directly means splitting into one, two, three and four aces. Counting the complement is one calculation, so start there.
A hand with no ace is five cards drawn from the 48 non-aces.
Subtract, and every hand left has an ace in it — because a hand either has none or has some, with nothing in between.
So a third of all hands hold at least one ace, which is far more than the phrase four aces in fifty-two cards suggests.
Now the check. Count exactly one ace, exactly two, exactly three and exactly four, then add. Four separate calculations, and the total agrees to the last digit.
Answer
The tool prints 886,656, 6 digits and log₁₀ = 5.9478. Step 5 is not decoration. At least one is the phrase most often counted as 4 × C(48, 4) = 778,320 — choose an ace, then fill around it — and that number is wrong because a two-ace hand is produced twice by the recipe, once from each of its aces. The complement can never make that mistake, which is why it is the first thing to reach for whenever a question says at least one.
Forty, thirty-five and twenty-eight members across three clubs is not 103 people. Find the real headcount, then split it into who belongs to one club, two, or all three. This is Inclusion-Exclusion, three-set union, with pairwise overlaps of 12, 10 and 9 and a triple overlap of 4.
Add the three rolls. Anyone in two clubs has now been counted twice and anyone in all three has been counted three times, so 103 is an upper bound and nothing more.
Subtract each pairwise overlap. Someone in exactly two clubs is now counted correctly — but someone in all three has been counted three times and subtracted three times, so they have vanished entirely.
Add the triple overlap back to restore them. That is the whole of inclusion–exclusion for three sets: add the singles, subtract the pairs, add the triple.
The union does not say how those 76 are distributed, and the same three inputs answer that too. Weight the pairs by two and the triple by three to strip out everyone with more than one membership.
The rest follows: 19 people belong to exactly two clubs, and the three groups add back to 76.
Answer
The tool prints 76, 2 digits and log₁₀ = 1.8808. The alternating signs are a repair rather than a mnemonic: each term fixes the previous one's overshoot, and it alternates because every fix overshoots the other way. That is also why the formula grows so fast — four sets need fifteen terms, and n sets need 2ⁿ − 1. Long before that is practical, the complement in problem 9 is the better instrument.
Eight people draw names for Secret Santa, and 14,833 of the 40,320 possible draws leave nobody holding their own name. Derive that count, then ask how many people typically do draw themselves. This is Special cases, derangement, with n = 8.
A derangement is a permutation with no fixed point. Inclusion–exclusion over the eight this person drew themselves events gives an alternating sum.
That sum is the first nine terms of the series for e⁻¹, and everything it omits is smaller than 1/9! = 2.8 × 10⁻⁶.
Multiply out and round: 14,833 draws in which nobody is holding their own name.
As a fraction that is 0.36788, against e⁻¹ = 0.367879 — agreement to five decimal places, at eight people, and it barely moves for larger groups.
Now a different question, and an easier one. Each person draws their own name with probability 1/n, and expectations add whether or not the events are independent, so the expected number of self-draws is exactly 1 — for eight people, and for eight hundred.
Answer
The tool prints 14,833, 5 digits and log₁₀ = 4.1712. Step 5 explains step 4. If the average number of self-draws is 1 whatever the group size, the chance of getting none of them cannot depend much on group size either — and for a rare-event count with mean 1, that chance is e⁻¹. The constant is not a curiosity here. It is the answer to how likely is zero when the average is one, a question that arrives constantly outside combinatorics.
442 shortest routes cross a 7 × 5 grid when one cell is blocked. Count all of them, count the ones through the blocked cell, and subtract. Then find the cell that would hurt most. This is Special cases, lattice path, with 7 east steps, 5 north steps and the block at (3, 2).
Every shortest route is twelve steps long, seven of them east and five north in some order. So a route is nothing but a choice of which steps are the eastward ones.
A route through the blocked cell is two independent routes glued at that cell: corner to cell, cell to far corner. Multiply, because every first half pairs with every second half.
Subtract, and what remains is exactly the routes that miss the cell.
That single cell was carrying 44% of all traffic — one blockage takes nearly half the routes.
But it is not the worst cell to lose. The cell one step east of the start carries 462 routes, 58% of them, because every route that begins with an east step must pass through it.
Answer
The tool prints 442, 3 digits and log₁₀ = 2.6454. Step 5 contradicts the picture. The blocked cell looks most damaging near the middle, where the routes appear to bunch; the arithmetic says cells near a corner carry more, because the count through a cell is a product of two binomial coefficients and near a corner one of them covers almost the whole grid. Counting paths through each node, rather than looking at the map, is also how redundancy is measured in a real network.