advent-0.1.0.0: Advent of Code common library
Copyright(c) Eric Mertens 2017
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Advent.Permutation

Description

Common permutations of a finite collection of elements and operations on them.

Synopsis

Documentation

data Permutation (n :: Nat) Source #

Permutations of n elements

Instances

Instances details
KnownNat n => Group (Permutation n) Source # 
Instance details

Defined in Advent.Permutation

KnownNat n => Monoid (Permutation n) Source # 
Instance details

Defined in Advent.Permutation

Semigroup (Permutation n) Source #

a <> b is the permutation that first permutes with a and then with b.

Instance details

Defined in Advent.Permutation

Read (Permutation n) Source # 
Instance details

Defined in Advent.Permutation

Show (Permutation n) Source # 
Instance details

Defined in Advent.Permutation

Eq (Permutation n) Source # 
Instance details

Defined in Advent.Permutation

Ord (Permutation n) Source # 
Instance details

Defined in Advent.Permutation

runPermutation :: forall a (n :: Nat). (Int -> a) -> Permutation n -> [a] Source #

mkPermutation :: forall (n :: Nat). KnownNat n => (Int -> Int) -> Permutation n Source #

Given a function mapping incoming indices to outgoing ones, construct a new permutation value.

swap :: forall (n :: Nat). KnownNat n => Int -> Int -> Permutation n Source #

Permutation generated by swapping the elements at a pair of indices.

rotateRight :: forall (n :: Nat). KnownNat n => Int -> Permutation n Source #

Permutation generated by rotating all the elements to the right.

rotateLeft :: forall (n :: Nat). KnownNat n => Int -> Permutation n Source #

Permutation generated by rotating all the elements to the left.

invert :: forall (n :: Nat). Permutation n -> Permutation n Source #

Permutation generated by inverting another permutation.

isValid :: forall (n :: Nat). Permutation n -> Bool Source #

Validate a permutation. A valid permutation will map each element in the input to a unique element in the output.

size :: forall (n :: Nat). Permutation n -> Int Source #

Size of the list of elements permuted.

backwards :: forall (n :: Nat). KnownNat n => Permutation n Source #

Permutation generated by reversing the order of the elements.

cycles :: forall (n :: Nat). Permutation n -> [[Int]] Source #

Compute the disjoint cycles of the permutation.

>>> cycles (swap 1 2 <> swap 3 4 <> swap 4 5 :: Permutation 6)
[[0],[1,2],[3,4,5]]

order :: forall (n :: Nat). Permutation n -> Int Source #

Compute the order of a permutation.

>>> order (swap 1 2 <> swap 3 4 <> swap 4 5 :: Permutation 6)
6