Combinatorics

Overview


Combinatorics is a mathematical subject which counts of the number of groups within a given set of items. It is used extensively in probability and statistics.

Permutations


A permutation is a collection of items, drawn from a second collection (without replacement) where the ordering matters. That is, two collections of the same items would not be considered as the same permuation if the order of the items differs.

Given a collections of n items, one can compute the number of permutations of k items taken from the given collection. This is often written as a function, P(n,k). That is, the number of permutations of n things taken k at a time.

The combinatorics module provides a method for computing all permutations of a set of items. It takes two inputs, the first being the set of items, the second being the number of items to take at the same time.


let cn = await import('/lib/combinatorics/v1.0.0/combinatorics.mjs');
//items to be permuted
let items = [1,2,3,4,5,6,7,8,9];

//get all permuations of 3 of the numbers 
let permutations = cn.permutations(items, 3);
					
Try it!


Combinations


Combinations are similar to permutations, but in this case, the ordering does not matter. That is, two sets with the same items are considered the same regardless of how they are ordered. Because of this equality, there will be fewer combinations of items than permutations.

The number of combinations of n things taken k at a time is written as
{% \binom{n}{k} %}
The combinatorics module also includes a method for calculating possible combinations from a set of items.

This example demonstrates a simple calculation of an average. The average function takes an array of numbers and calculates an average.


let cn = await import('/lib/combinatorics/v1.0.0/combinatorics.mjs');
//items to be combined
let items = [1,2,3,4,5,6,7,8,9];

//get all combinations of 3 of the numbers
let combinations = cn.combinations(items, 3);
					
Try it!

Contents