Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Rubiks Cube
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Rubik's Cube represented with faces == Here is a simple model for a [http://en.wikipedia.org/wiki/Rubik%27s_cube Rubik's Cube]. The basic idea is that you only need to keep track of the corners and edges. Each corner has three faces. Each edge has two faces. Keeping track of a face means telling where it was before any moves were made and where it is in the current state. Choose, as a convention, the ordering, right, up, front. (Math/Physics folk: this is in anology to the "right hand rule" convention which assigns an ordering to the "x y and z" axes and determines that z will be "out of" rather than "into" the plane) For example, the lower left front corner would be represented as (Left Left) (Down Down) (Front Front) before any moves are made Then, after a rotation about the Front face, the same corner, now in the right down front position would be represented as (Left Down) (Down Right) (Front Front). Edit by somebody else: I'm not the author of this, however I think there are some erros in the definition of all the datas below. I think they all are missing the constructor, when you're reading the code keep that in mind. also: You can read the paper by Richard E. Korf named "Finding Optimal Solutions to Rubik's Cube Using Pattern Databases."[http://www.cs.princeton.edu/courses/archive/fall06/cos402/papers/korfrubik.pdf] to have a better understanding of the Edged/Corners approach <haskell> #!/usr/bin/runhugs module Main (main) where main :: IO () main = do putStr "Not your ordinary language" data Cube = Edges Corners type Edges = [Edge] -- or Edges = Edge Edge Edge Edge Edge Edge Edge Edge Edge Edge Edge Edge type Corners = [Corner] data Edge = Face Face data Corner = Face Face Face data Face = Was Is data Was = R|L|U|D|F|B data Is = R|L|U|D|F|B </haskell>
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width