Constrained nCr/nPr Calculator (Required & Forbidden Items)
Use this page to count outcomes for common discrete-math tasks: ordered arrangements (permutations), unordered selections (combinations), role-based team selection, and simple shift assignment counting. The constraint solver section focuses on two practical constraints: k required items that must be included and f forbidden items that are excluded from the pool.
How this calculator works
Counting problems often look different on the surface (podium finishes, committees, schedules), but many reduce to choosing r items from n distinct items. The key decision is whether order matters. If order matters, you are counting arrangements; if order does not matter, you are counting selections.
- Permutation (nPr): order matters (e.g., 1st/2nd/3rd place, seat assignments, PIN codes without repeated digits).
- Combination (nCr): order does not matter (e.g., a committee, a set of toppings, a shortlist of candidates).
Constraint model used on this page
The constraint solver uses count-based constraints. You are not naming specific items; you are saying “there are k specific items that must be included” and/or “there are f specific items that must be excluded.” Items are assumed distinct and selections are without replacement.
This model is intentionally simple and fast. It is useful when you know how many items are forced in or removed but you do not need to model complex relationships (for example, “at least one from group A” or “Alice and Bob cannot both be selected”). Those richer rules typically require inclusion–exclusion, recursion, or explicit enumeration.
Formulas
Let allowed = n − f. If k items are required, they are fixed into the selection, leaving r − k remaining picks from allowed − k items.
- Combinations: valid = C(allowed − k, r − k)
- Permutations: valid = P(allowed − k, r − k) (counts arrangements of the non-required portion)
If k = 0, the formulas reduce to C(allowed, r) or P(allowed, r). If any rule makes the selection impossible (for example r > n, k > r, or allowed < r), the result is 0.
Worked example (constraints)
Suppose you have n = 10 items and you want to select r = 4 items. Two items are required (k = 2) and one item is forbidden (f = 1).
- Allowed items after forbidding: allowed = 10 − 1 = 9
- Remaining picks after required items: r − k = 4 − 2 = 2
- Remaining pool after required items: allowed − k = 9 − 2 = 7
- Valid combinations: C(7, 2) = 21
Interpretation: there are 21 valid selections of size 4 that include the 2 required items and avoid the 1 forbidden item.
How to use the constraint solver (practical checklist)
The constraint solver is designed for quick “how many ways?” questions. To avoid common mistakes, use this checklist before trusting the number:
- Confirm distinctness: the formulas assume all items are distinct. If items are identical (e.g., identical balls), the count changes.
- Confirm no repetition: the selection is without replacement. If repetition is allowed, you need a different model.
- Check feasibility: if r > n, or if forbidding leaves fewer than r allowed items, the answer must be 0.
- Interpret k correctly: k means “these specific items must be included,” not “at least k items from a category.”
- Interpret f correctly: f means “these specific items are removed,” not “avoid selecting f items.”
Why results can be huge (and what the formatting means)
Combinatorics grows quickly. Even moderate inputs can produce extremely large counts because factorials multiply many integers together. This page formats large values in scientific notation (for example, 3.141 × 10^12) when the exact integer is too large to display comfortably. JavaScript uses floating-point numbers, so extremely large results can exceed safe integer precision; the formatted output is still useful for magnitude and comparison, but it may not represent an exact integer once values become enormous.
Team selection and scheduling tabs
The Team Selection tab multiplies combinations across roles (forwards, midfielders, defenders, goalkeepers). The Scheduling tab counts feasible worker-to-shift assignments under a maximum-shifts-per-worker constraint. These are simplified counting models intended for quick estimates.
Permutations vs combinations quick reference
| Aspect | Permutation | Combination |
|---|---|---|
| Order importance | Order matters (ABC ≠ BAC) | Order does not matter (ABC = BAC) |
| Formula | P(n, r) = n! / (n − r)! | C(n, r) = n! / (r!(n − r)!) |
| Typical use | Rankings, seating, sequences | Teams, committees, subsets |
| Quick intuition | Usually much larger because each selection can be arranged in many orders. | Smaller because it collapses all orderings of the same set into one outcome. |
Assumptions and limitations
- Inputs are treated as non-negative integers; items are distinct.
- No repetition (sampling without replacement).
- Very large results may overflow JavaScript number precision; the page formats large values in scientific notation.
- Constraint solver supports only count-based required/forbidden constraints (not group rules like “at least one from A”).
- For permutations with required items, this page counts arrangements of the non-required portion as implemented in the script.
More examples you can model with this page
If you are learning combinatorics, it helps to translate real questions into n, r, k, and f. Here are several examples that match the calculator’s assumptions:
- Hiring shortlist: You have n applicants and want a shortlist of r. If k candidates must be included (e.g., internal referrals) and f candidates are disqualified, use the constraint solver in combination mode.
- Speaker lineup: You have n potential speakers and need r slots. If order matters (opening keynote vs closing talk), use permutation mode.
- Access codes: You have n symbols and want a code of length r without repetition. If some symbols are banned (f), remove them via forbidden count and use permutation mode.
- Product bundles: You have n products and want bundles of size r. If a set of k products must be included in every bundle, use combination mode with required count.
For each example, sanity-check the output by changing one input at a time. If you increase f (more forbidden items), the count should not increase. If you increase r (choose more items), the count may increase or decrease depending on n and constraints, but it should never be negative.
Interpreting the number: count vs probability
This calculator returns a count: how many valid outcomes exist. A probability requires an additional assumption about how outcomes are generated. For example, if every combination is equally likely, then the probability of a specific combination is 1 / C(n, r). If outcomes are not equally likely (for example, some workers are more likely to be scheduled, or some candidates are more likely to be selected), then the count alone does not determine probability. Use the count as a measure of “search space size” and as a way to compare scenarios consistently.
