Overview
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 formula for the number of permutations is given:
{% P(n, k) = \frac{n!}{(n-k)!} %}
API
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!