
Permutations and combinations
Calculate permutations and combinations with clear inputs and assumptions.
Your inputs stay in your browser. Displayed results are rounded to a maximum of 12 significant digits.
Method and assumptions
Method version 1.0.0 · Updated
Calculate
Formula: Calculate permutations and combinations with clear inputs and assumptions.
Calculate permutations and combinations with clear inputs and assumptions.
- n
- n
- r
- r
- mode
- Calculation
Results are estimates where noted and depend on the entered assumptions.
Calculate with code
These short examples use the same inputs and core calculation as this tool. Adapt validation and formatting to your application.
JavaScript
const n = 5, r = 2;
const factorial = n => n <= 1 ? 1 : n * factorial(n - 1);
console.log(factorial(n) / factorial(n-r) / factorial(r)); // C(5,2) = 10TypeScript
const factorial = (n: number): number => n <= 1 ? 1 : n * factorial(n - 1);
const n = 5, r = 2;
console.log(factorial(n) / factorial(n-r) / factorial(r)); // 10 combinationsPython
import math
n, r = 5, 2
print(math.comb(n, r), math.perm(n, r)) # 10 combinations, 20 permutationsJava
int n=5, r=2;
long combinations = 1; for (int i=1;i<=r;i++) combinations = combinations*(n-r+i)/i;
System.out.println(combinations); // 10C#
int n=5, r=2;
double combinations = Enumerable.Range(1,r).Aggregate(1.0,(v,i)=>v*(n-r+i)/i);
Console.WriteLine(combinations); // 10