Everything on the site.

Big-O notationAlgorithms · Count the steps in real loops, then compare n, n log n, n² and 2ⁿ on a live chart.RecursionAlgorithms · Watch frames push and pop on the call stack for factorial and Fibonacci.BFS vs DFSAlgorithms · A queue against a stack: draw a graph and see which order each search visits it in.Sorting algorithmsAlgorithms · Seven sorts on the same input, with comparison, swap and write counts side by side.Binary searchAlgorithms · Halve the range, probe the middle, repeat: with lo, mid and hi drawn on the array.Sets, relations and functionsDiscrete maths · Shade any set expression on a Venn diagram and test a relation for its properties.Proof by inductionDiscrete maths · Four worked proofs revealed one step at a time, and a broken one to diagnose.CombinatoricsDiscrete maths · An exact nPr and nCr calculator, and a Pascal’s triangle that shows its own addition rule.Boolean algebraDiscrete maths · The laws, De Morgan, and normal forms, with a truth-table generator built in.Finite-state machinesTheory · Build a DFA in a table, see it drawn, and run strings through it one symbol at a time.Domain theoryTheory · Why recursion needs least fixed points, and how CPOs, Scott continuity and powerdomains supply them.Truth table generatorTools · Expression in, truth table out: with DNF, CNF, a minimal form and LaTeX.Graph traversal visualiserTools · Draw a graph, then animate BFS, DFS and Dijkstra with the frontier shown.Recursion tree visualiserTools · Paste a recursive function or a recurrence and see its call tree and call count.Gradient descentML maths · Drag the starting point, set the learning rate, and watch it converge or blow up.Vectors and embeddingsML maths · Bend the plane with a 2×2 matrix and measure how close toy word vectors are.Softmax and cross-entropyML maths · Edit the logits and watch the probabilities, the loss and the gradient update live.Attention mechanismML maths · Q, K and V for three tokens, a live score heatmap, and the weighted sum of values.Formatting a CS paper in LaTeXLaTeX · Page limits, \documentclass, front matter, theorem environments and the bibliography.Camera-ready checklistLaTeX · Fonts embedded, PDF/A, copyright form, source bundle, and why final versions get rejected.LaTeX templatesLaTeX · Where the official classes live, plus a minimal article template you can copy.Boolean algebra calculatorTools · A Boolean expression simplifier that names the law used at every step.K-map solverTools · Fill in a Karnaugh map and see the groups, the minimal SOP and POS, and the essential terms.Logic gate simulatorTools · Wire up gates, flip the switches, and get the truth table and expression of your circuit.Regex to NFA converterTools · Type a regular expression and watch Thompson’s construction build its NFA, fragment by fragment.NFA to DFA converterTools · Enter an NFA or a regex and step through the subset construction, then minimise the DFA.DFA simulatorTools · Edit a DFA, run strings through it step by step, batch-test them and share the machine as a link.Regular expressions to automataTheory · Regex to NFA to DFA to minimal DFA, worked through on one example with every set shown.The halting problemTheory · Why no program can tell whether every program halts, with the paradox program played out.Pigeonhole principleDiscrete maths · n pigeons, k holes: why some hole gets ⌈n/k⌉, and the surprising things that follows from it.Dijkstra’s algorithmAlgorithms · Shortest paths with a priority queue: a worked table, a proof, and a graph you can redraw.Hash functionsAlgorithms · Keys in, buckets out: hash a word four ways, then watch chaining and probing handle collisions.Sorting algorithm visualizerTools · Up to seven sorts race on the same data, then step through any one of them line by line.LaTeX table generatorTools · Type or paste a table, merge cells, pick booktabs, and copy clean tabular code.Combination calculatorTools · Exact nCr with the cancelling shown, combinations with repetition, and a full list for small n.Permutation calculatorTools · nPr, nʳ, anagrams like MISSISSIPPI and round-table seatings, with exact working.AlgorithmsSection · Step-through visualisations of sorting, searching, recursion, graph traversal, Dijkstra’s algorithm, hash functions and Big-O growth, with pseudocode that follows along.Discrete mathsSection · Sets, relations and functions, proof by induction, counting, the pigeonhole principle and Boolean algebra, explained with worked examples and interactive checkers.TheorySection · Finite-state machines, regular expressions and automata, the halting problem, and the mathematical semantics of programming languages, explained from first principles.ML mathsSection · Gradient descent, vectors and embeddings, softmax and cross-entropy, and attention, each with a formula, a worked numeric example and a live version.ToolsSection · Free browser tools: truth tables, Boolean simplification, K-maps, logic gates, nCr and nPr, regex to NFA to DFA, sorting and graph visualisers, and LaTeX tables.LaTeXSection · How to format a CS conference or workshop paper in LaTeX, a camera-ready checklist, and a minimal template you can adapt.
Free tool

Combination calculator (nCr) with step-by-step working

Work out how many ways there are to choose r items from n when the order doesn’t matter. The calculator gives the exact value of nCr however large it gets, shows the working step by step, lists every combination for small cases, and handles selections with repetition too.

Interactive: nCr calculator with working, odds and enumerationUpdated

Combination calculator (nCr)

Step-by-step working

    List every combination

    The combination formula

    The number of ways to choose rr items from nn distinct items, ignoring order and without using any item twice, is the binomial coefficient

    (nr)=nCr=C(n,r)=n!r! (n−r)!.\binom{n}{r} = {}^{n}C_{r} = C(n, r) = \frac{n!}{r!\,(n-r)!}.

    All four notations mean the same number; textbooks and calculators use whichever is easiest to type. It is read “nn choose rr”. The exclamation mark is the factorial: n!=n×(n−1)×⋯×2×1n! = n \times (n-1) \times \cdots \times 2 \times 1, with 0!=10! = 1.

    Why the formula works

    Start by counting ordered selections. There are nn ways to pick the first item, n−1n-1 for the second, and so on, which gives n!/(n−r)!n!/(n-r)! ordered lists: the permutations P(n,r)P(n, r). A combination is one of these lists with the order forgotten. Each set of rr items can be put in order in r!r! ways, so every combination was counted r!r! times. Dividing gives the formula:

    C(n,r)=P(n,r)r!=n!r! (n−r)!.C(n, r) = \frac{P(n, r)}{r!} = \frac{n!}{r!\,(n-r)!}.

    Worked example: choose a committee of 3 from 10 people

    1. Substitute into the formula: C(10,3)=10!3! 7!C(10, 3) = \dfrac{10!}{3!\,7!}.
    2. Cancel 7!7!, which appears on the top and the bottom: 10×9×83×2×1\dfrac{10 \times 9 \times 8}{3 \times 2 \times 1}.
    3. Multiply out: 7206\dfrac{720}{6}.
    4. Divide: 120 committees.

    If the three roles were different (chair, secretary, treasurer), order would matter and the answer would be P(10,3)P(10, 3) = 720, six times as many.

    Step 2 is the trick for calculating by hand: never compute the large factorials. Keep only the top rr factors of n!n! and divide by r!r!. The calculator does the same, and it uses the symmetry (nr)=(nn−r)\binom{n}{r} = \binom{n}{n-r} first when that gives a shorter product, so C(100,97)C(100, 97) is worked as C(100,3)C(100, 3).

    Combination or permutation?

    Ask one question: would rearranging the chosen items give a different outcome?

    SituationOrder matters?Use
    Lottery numbers, a hand of cards, pizza toppings, a teamNoCombination (nr)\binom{n}{r}
    Race podium, a password, seating in a row, a PINYesPermutation P(n,r)P(n, r) or nrn^r
    Scoops of ice cream or donuts where flavours can repeatNo, with repetition(n+r−1r)\binom{n+r-1}{r}

    The same objects can fall on either side depending on the question. Three people chosen from ten form (103)\binom{10}{3} groups, but if you then line them up for a photo, each group gives 3!=63! = 6 photos.

    Combinations with repetition

    Tick Repetition allowed when the same kind can be chosen more than once and only how many of each you take matters: six donuts from four flavours, or three coins from pennies, nickels and dimes. The answer is

    ( ⁣(nr) ⁣)=(n+r−1r).\left(\!\binom{n}{r}\!\right) = \binom{n + r - 1}{r}.

    The reason is the stars and bars picture. Write the rr chosen items as stars and separate the nn kinds with n−1n-1 bars: ★★|★||★★★ means two of the first flavour, one of the second, none of the third and three of the fourth. Every selection is one such row of n+r−1n + r - 1 symbols, and a row is fixed once you choose which rr of the positions hold stars. For six donuts from four flavours that gives (96)\binom{9}{6} = 84 different boxes.

    Common combination problems

    Lottery odds

    In a 6-from-49 lottery the order the balls are drawn in doesn’t matter, so there are (496)\binom{49}{6} = 13,983,816 possible tickets. One ticket wins the jackpot with probability 1 in 13,983,816. Try it with the “Lottery” example above.

    Card hands

    A five-card hand from a standard deck: (525)\binom{52}{5} = 2,598,960. To count hands with at least one ace, count the complement: hands with no ace come from the 48 other cards, so the answer is (525)−(485)\binom{52}{5} - \binom{48}{5} = 886,656. Subtracting the complement is almost always easier than adding up “exactly one, exactly two, …”.

    Choosing from two groups

    A class has 6 girls and 5 boys. A team of two girls and two boys can be picked in (62)×(52)\binom{6}{2} \times \binom{5}{2} = 150 ways, by the product rule. A team of 4 with at least one boy: (114)−(64)\binom{11}{4} - \binom{6}{4} = 315.

    Subsets

    Twelve toppings and you want exactly three: (123)\binom{12}{3} = 220 pizzas. Any number of toppings at all: 212=40962^{12} = 4096, because each topping is independently in or out. Summing (12r)\binom{12}{r} over every rr gives the same 4096, which is the row-sum identity of Pascal’s triangle.

    Mistakes to avoid
    • Counting ordered lists when order doesn’t matter. Picking “first a red card, then a black card” and multiplying counts every pair twice.
    • Double counting with “at least”. Counting hands with at least one ace as 4×(514)4 \times \binom{51}{4} (pick an ace, then any four cards) counts a hand with two aces twice. Subtract the complement instead.
    • Rounding. A floating-point calculator loses digits beyond about 101510^{15}. This calculator uses exact big-integer arithmetic, so (1000500)\binom{1000}{500} comes out to all 300 digits.

    Useful identities

    • Symmetry: (nr)=(nn−r)\binom{n}{r} = \binom{n}{n-r}. Choosing what to take is choosing what to leave.
    • Pascal’s rule: (nr)=(n−1r−1)+(n−1r)\binom{n}{r} = \binom{n-1}{r-1} + \binom{n-1}{r}, the addition rule of Pascal’s triangle.
    • Row sum: ∑r=0n(nr)=2n\sum_{r=0}^{n} \binom{n}{r} = 2^n, the number of subsets of an nn-element set.
    • Edge cases: (n0)=(nn)=1\binom{n}{0} = \binom{n}{n} = 1, and (nr)=0\binom{n}{r} = 0 when r>nr > n.
    • Binomial theorem: (x+y)n=∑r(nr)xryn−r(x+y)^n = \sum_{r} \binom{n}{r} x^r y^{n-r}, which is where the name “binomial coefficient” comes from.

    How the calculator works

    Everything runs in your browser with JavaScript’s BigInt, so results are exact integers with no rounding. To avoid ever building a huge factorial, it multiplies and divides alternately: after step ii the running value is exactly (n−r+ii)\binom{n-r+i}{i}, which is always a whole number, so every division is exact. Values with ten or more digits are also shown in scientific notation, and the page address updates as you type so you can bookmark or share a calculation.

    For the theory behind the four basic counting formulas, with Pascal’s triangle drawn interactively, see permutations, combinations and Pascal’s triangle. For ordered selections, use the permutation calculator.

    References

    1. R. L. Graham, D. E. Knuth and O. Patashnik, Concrete Mathematics, 2nd ed., Addison-Wesley, 1994. Chapter 5, “Binomial coefficients”.
    2. K. H. Rosen, Discrete Mathematics and Its Applications, 8th ed., McGraw-Hill, 2019. Sections 6.3 and 6.5.
    3. “Combination”, Wikipedia.