twentyseven-0.0.0: Rubik's cube solver

Safe HaskellNone
LanguageHaskell2010

Rubik.Misc

Contents

Description

General functions for the twentyseven project

Synopsis

Documentation

flatIndex :: Int -> Int -> Int -> Int Source

Convert 2D indices to 1D.

\n x y -> x * n + y

Applicative

zipWith' :: Applicative f => (a -> b -> c) -> f a -> f b -> f c Source

sequence' :: Applicative f => [f a] -> f [a] Source

Lists

rotate :: Int -> [a] -> [a] Source

Rotation:

rotate 3 [1,2,3,4,5,6,7] == [4,5,6,7] ++ [1,2,3]

subs :: Int -> a -> [a] -> [a] Source

Substitute the n-th element.

insert' :: Int -> a -> [a] -> [a] Source

Insert before the n-th element.

inverseList :: Int -> [Int] -> [Int] Source

If l is a permutation list (replaced-by) of length n, inverseList n l is its inverse permutation.

composeList :: [a] -> [Int] -> [a] Source

Backpermute. Substitute every index in the second list with the corresponding element in the first.

listSeq :: [a] -> b -> b Source

Strict in every element of the list.

Vectors

type Vector = Vector Source

Unboxed vectors

isPermutationVector :: Vector Int -> Bool Source

Permutation of [0 .. length v].

signPermutationVector :: Vector Int -> Int Source

Sign of a permutation vector.

idVector :: Int -> Vector Int Source

idVector n == fromList [0 .. n - 1]

inverseVector :: Vector Int -> Vector Int Source

If v is a permutation, inverseVector v is its inverse permutation.

composeVector :: Unbox a => Vector a -> Vector Int -> Vector a Source

Permutation composition: (p . q) x == p (q x).

composeVector u v ! i == u ! (v ! i)

Groups

class Monoid a => Group a where Source

Class for groups:

a <> (b <> c) == (a <> b) <> c -- Associative property
a <> iden == a -- Neutral element
iden <> a == a
a <> inverse a == iden -- Inverse
inverse a <> a == iden

Methods

inverse :: a -> a Source

iden :: Group a => a Source

Alias for mempty

(<>^) :: (Integral int, Group a) => a -> int -> a infixr 8 Source

Exponentiation, negative indices are supported.

conjugate :: Group a => a -> a -> a Source

Conjugation:

s `conjugate` a = inverse s <> a <> s

(??) :: Group a => a -> a -> a Source

Conjugation:

s `conjugate` a = inverse s <> a <> s

Combinatorics

fact :: Int -> Int Source

Factorial

choose :: Int -> Int -> Int Source

Binomial coefficient:

choose n k == fact n `div` (fact k) * (fact (n - k))

iFind :: (Integral a, Ord a, Vector v a) => a -> v a -> Maybe Int Source

Interpolation search for Int

bool :: a -> a -> Bool -> a Source

Flipped "if"

chunk :: Int -> [a] -> [[a]] Source

Equal sized chunks

partition' :: (a -> a -> Bool) -> [a] -> [[a]] Source

Generalized partition

tagOf :: tag a b -> tag' a b' -> tag a b Source

asProxyTypeOf :: a -> proxy a -> a Source

proxyUnwrap :: proxy (f a) -> Proxy a Source

(<&>) :: Functor f => f a -> (a -> b) -> f b Source