Permutations. See: Donald E. Knuth: The Art of Computer Programming, vol 4, pre-fascicle 2B.
- _permutations :: Int -> [[Int]]
- countPermutations :: Int -> Integer
- permute :: (Eq a, Ord a) => [a] -> [[a]]
- countPermute :: (Eq a, Ord a) => [a] -> Integer
- fasc2B_algorithm_L :: (Eq a, Ord a) => [a] -> [[a]]
Permutations of distinct elements
_permutations :: Int -> [[Int]]Source
Permutations of [1..n] in lexicographic order, naive algorithm.
countPermutations :: Int -> IntegerSource
# = n!
Permutations of a multiset
permute :: (Eq a, Ord a) => [a] -> [[a]]Source
Generates all permutations of a multiset. The order is lexicographic.
countPermute :: (Eq a, Ord a) => [a] -> IntegerSource
# = \frac { (sum_i n_i) ! } { \prod_i (n_i !) }
fasc2B_algorithm_L :: (Eq a, Ord a) => [a] -> [[a]]Source
Generates all permutations of a multiset (based on "algorithm L" in Knuth; somewhat less efficient). The order is lexicographic.