Safe Haskell | None |
---|---|
Language | Haskell2010 |
Cubie representation.
A Rubik's cube is the cartesian product of a permutation of cubies and an action on their orientations.
- class CubeAction a where
- cubeAction :: a -> Cube -> a
- class FromCube a where
- data Cube = Cube {}
- solvable :: Cube -> Bool
- numCorners :: Int
- data CornerPermu
- data CornerOrien
- data Corner = Corner {}
- cornerPermu :: Vector Int -> Maybe CornerPermu
- cornerOrien :: Vector Int -> Maybe CornerOrien
- fromCornerPermu :: CornerPermu -> Vector Int
- fromCornerOrien :: CornerOrien -> Vector Int
- numEdges :: Int
- data EdgePermu
- data EdgeOrien
- data Edge = Edge {}
- edgePermu :: Vector Int -> Maybe EdgePermu
- edgeOrien :: Vector Int -> Maybe EdgeOrien
- fromEdgePermu :: EdgePermu -> Vector Int
- fromEdgeOrien :: EdgeOrien -> Vector Int
- stringOfCubeColors :: Cube -> String
- toFacelet :: Cube -> Facelets
- colorFaceletsToCube :: ColorFacelets -> Either [Int] (Maybe Cube)
- numUDSliceEdges :: Int
- data UDSlicePermu
- data UDSlice
- data UDSlicePermu2
- data UDEdgePermu2
- type FlipUDSlice = (UDSlice, EdgeOrien)
- type FlipUDSlicePermu = (UDSlicePermu, EdgeOrien)
- uDSlicePermu :: Vector Int -> Maybe UDSlicePermu
- uDSlice :: Vector Int -> Maybe UDSlice
- uDSlicePermu2 :: Vector Int -> Maybe UDSlicePermu2
- uDEdgePermu2 :: Vector Int -> Maybe UDEdgePermu2
- edgePermu2 :: UDSlicePermu2 -> UDEdgePermu2 -> EdgePermu
- fromUDSlicePermu :: UDSlicePermu -> Vector Int
- fromUDSlice :: UDSlice -> Vector Int
- fromUDSlicePermu2 :: UDSlicePermu2 -> Vector Int
- fromUDEdgePermu2 :: UDEdgePermu2 -> Vector Int
- conjugateUDSlicePermu :: Cube -> UDSlicePermu -> UDSlicePermu
- conjugateFlipUDSlice :: Cube -> FlipUDSlice -> FlipUDSlice
- conjugateFlipUDSlicePermu :: Cube -> FlipUDSlicePermu -> FlipUDSlicePermu
- conjugateCornerOrien :: Cube -> CornerOrien -> CornerOrien
Complete cube
class CubeAction a where Source
Group action of Cube
on type a
x `cubeAction` iden == x (x `cubeAction` a) `cubeAction` b == x `cubeAction (a <> b)
It seems that with proper additional laws
between FromCube
and Group
instances,
it may be possible to automatically deduce a default CubeAction
instance.
cubeAction a = (a <>) . fromCube
This module defines representations of right cosets (Hg where g :: Cube
)
of certain subgroups H of the Rubik group Cube
, which acts on the right of
the set of cosets.
cubeAction :: a -> Cube -> a Source
A cube is given by the positions of its corners and edges.
Cubes are identified with the permutations that produce them starting from the solved cube.
The cube permutation composition (class
) is defined
"in left to right order", so that the sequence of movements
"Group
Cube
x
then y
then z
" is represented by x <> y <> z
.
Solvability test
Corners
numCorners :: Int Source
numCorners = 8
data CornerPermu Source
Cubie permutation is in replaced-by representation.
Eq CornerPermu Source | |
Show CornerPermu Source | |
Monoid CornerPermu Source | |
Group CornerPermu Source | |
CubeAction CornerPermu Source | |
FromCube CornerPermu Source | |
RawEncodable CornerPermu Source | The number of elements of every set is given. 8! = 40320 |
data CornerOrien Source
Corner | |
|
(De)construction
cornerPermu :: Vector Int -> Maybe CornerPermu Source
cornerOrien :: Vector Int -> Maybe CornerOrien Source
Check that the argument is a vector of senary (6) values of size 8 and wrap it.
In a solvable
Rubik's cube,
only ternary values are possible;
i.e., all elements must be between 0 and 2.
Their sum must also be a multiple of 3.
Orientation encoding
Corner orientations are permutations of 3 facelets.
They are mapped to integers in [0 .. 5]
such that [0, 1, 2]
are rotations (even permutations)
and [3, 4, 5]
are transpositions (although impossible in a Rubik's cube).
- 0. identity
- 1. counter-clockwise
- 2. clockwise
- 3. left facelet fixed
- 4. right facelet fixed
- 5. top (reference) facelet fixed
Edges
Cubie permutation is in replaced-by representation.
(De)construction
edgePermu :: Vector Int -> Maybe EdgePermu Source
Check that the argument is a permutation of size 12 and wrap it.
In a solvable
Rubik's cube,
its parity must be equal to that of the associated CornerPermu
.
edgeOrien :: Vector Int -> Maybe EdgeOrien Source
Check that the argument is a vector of binary values of size 12 and wrap it.
In a solvable
Rubik's cube, their sum must be even.
fromEdgePermu :: EdgePermu -> Vector Int Source
fromEdgeOrien :: EdgeOrien -> Vector Int Source
Conversions
stringOfCubeColors :: Cube -> String Source
colorFaceletsToCube :: ColorFacelets -> Either [Int] (Maybe Cube) Source
Convert from facelet to cubie permutation.
Evaluates to a Left
error if a combination of colors does not correspond to
a regular cubie from the solved cube: the colors of the facelets on one
cubie must be unique, and must not contain facelets of opposite faces.
The error is the list of indices of facelets of such an invalid cubie.
Another possible error is that the resulting configuration is not a
permutation of cubies (at least one cubie is absent, and one is duplicated).
In that case, the result is Right
Nothing
.
UDSlice
numUDSliceEdges = 4
data UDSlicePermu Source
Position of the 4 UDSlice edges (carried-to)
Position of the 4 UDSlice edges up to permutation (carried-to). The vector is always sorted.
data UDSlicePermu2 Source
Position of the 4 UDSlice edges (replaced-by), assuming they are all in that slice already.
data UDEdgePermu2 Source
Position of the 8 other edges (replaced-by), assuming UDSlice edges are in that slice already.
type FlipUDSlice = (UDSlice, EdgeOrien) Source
type FlipUDSlicePermu = (UDSlicePermu, EdgeOrien) Source
(De)construction
uDSlicePermu :: Vector Int -> Maybe UDSlicePermu Source
uDSlicePermu2 :: Vector Int -> Maybe UDSlicePermu2 Source
Wrap a permutation of size 4.
uDEdgePermu2 :: Vector Int -> Maybe UDEdgePermu2 Source
Wrap a permutation of size 8.
edgePermu2 :: UDSlicePermu2 -> UDEdgePermu2 -> EdgePermu Source
fromUDSlice :: UDSlice -> Vector Int Source
Symmetry
conjugateFlipUDSlice :: Cube -> FlipUDSlice -> FlipUDSlice Source
The conjugation is only compatible when the Cube
symmetry
leaves UDSlice edges stable, and either flips them all or none of them,
and either flips all 8 non-UDSlice edges or none of them.
conjugateFlipUDSlicePermu :: Cube -> FlipUDSlicePermu -> FlipUDSlicePermu Source
Expects UDSlice-stable symmetry
conjugateCornerOrien :: Cube -> CornerOrien -> CornerOrien Source
Expects UDSlice-stable symmetry.