Skip to content
πŸ› οΈToolsShed

Combinations & Permutations

Calculate nCr (combinations) and nPr (permutations) with step-by-step solutions.

About this tool

Combinations and permutations are fundamental concepts in probability, statistics, and discrete mathematics that help you count the number of ways to select or arrange items from a group. This calculator lets you compute nCr (the number of ways to choose r items from n items where order doesn't matter) and nPr (the number of ways to arrange r items from n items where order does matter), along with detailed step-by-step solutions to help you understand each calculation.

To use the tool, simply enter the total number of items (n) and the number of items you want to select or arrange (r), then choose whether you need combinations or permutations. The calculator instantly displays the result and breaks down the factorial operations so you can see exactly how the answer was derived. This is especially useful for homework, exam preparation, or verifying results in probability problems.

Frequently Asked Questions

Code Implementation

import math

# Combinations C(n, r): order doesn't matter
n, r = 10, 3
c = math.comb(n, r)
print(f"C({n},{r}) = {c}")  # 120

# Permutations P(n, r): order matters
p = math.perm(n, r)
print(f"P({n},{r}) = {p}")  # 720

# Manual calculation
def combinations(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

def permutations(n, r):
    return math.factorial(n) // math.factorial(n - r)

# All actual combinations
from itertools import combinations as combs, permutations as perms

items = ["A", "B", "C", "D"]
for combo in combs(items, 2):
    print(combo)  # ('A','B'), ('A','C'), ...

for perm in perms(items, 2):
    print(perm)   # ('A','B'), ('A','C'), ('B','A'), ...

# Combinations with repetition
from itertools import combinations_with_replacement
for c in combinations_with_replacement("ABC", 2):
    print(c)  # ('A','A'), ('A','B'), ...

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.