Count arrangements and selections with nPr, nCr, and repetition variants.
Permutations count ordered arrangements. If you choose r items from n in a specific order, the number of ways is nPr = n!/(n−r)!. Combinations count unordered selections; the order of the chosen items doesn't matter: nCr = n!/(r!(n−r)!). When repetition is allowed — the same item can be chosen more than once — permutations become nʳ and combinations become C(n+r−1, r).
Permutation (no repetition)
nPr = n! / (n−r)!
Combination (no repetition)
nCr = n! / (r! × (n−r)!)
Permutation (with repetition)
Permutations with repetition = nʳ
Combination (with repetition)
Combinations with repetition = C(n+r−1, r)
Order matters in permutations, not in combinations. Choosing the three people {Alice, Bob, Carol} for a committee is one combination but six permutations (ABC, ACB, BAC, BCA, CAB, CBA). Use permutations when sequence matters (race finishing positions, PIN codes); use combinations when it doesn't (lottery draws, team selection).
Use permutations with repetition (nʳ) when items can be reused: e.g., counting 4-digit PINs from digits 0–9 = 10⁴ = 10,000. Use combinations with repetition (C(n+r−1,r)) for unordered selections where repeats are allowed: e.g., choosing 3 ice cream scoops from 5 flavours when you can repeat flavours.
171! overflows JavaScript's float64 to Infinity. For n ≤ 170 the factorial stays representable. If you need exact arithmetic for larger n you would need a big-integer library, which this platform does not include.
The implementation uses k = min(r, n−r) and divides as it multiplies, keeping intermediate values small. This makes C(60, 30) = 118,264,581,564,861,424 computable exactly in float64, well beyond what a naive factorial ratio would handle.