Skip to main content

Module combinatorics

Module combinatorics 

Source

Enums§

CombinatoricsError

Functions§

count_combinations
Count combinations - the number of ways to pick n_choose items from n_total, where order does not matter.
count_permutations
Count permutations - the number of ways to pick n_choose items from n_total, where order matters.
derangements
Count derangements of n elements: permutations with no fixed points at all.
restricted_partition_count
Count ways to partition n labelled elements into exactly k unlabelled, non-empty blocks, each block’s size restricted to [block_min, block_max].
stirling_second_kind
Count surjections from an n-element set onto a k-element set: the Stirling number of the second kind S(n, k), i.e. the number of ways to partition n labelled elements into exactly k non-empty unlabelled blocks (a surjection onto k elements is exactly a choice of which block maps to which target element, and blocks are otherwise interchangeable until that assignment – so partitioning first and multiplying by k! elsewhere gives the surjection count; this function returns the partition count alone).