Difference between revisions of "Rubiks Cube"

From HaskellWiki
Jump to navigation Jump to search
Line 1: Line 1:
 
Here is a simple model for a [http://en.wikipedia.org/wiki/Rubik%27s_cube Rubik's Cube].
 
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.
My hope is to get people to see a rubik's cube as something other than "a problem to solve." It's a toy!
 
 
My two ideas are to get people to play with Haskel code _about_ the cube and (a separate idea, maybe to be explored in this model later) to make cubes with five colors, each edge and corner having the same coloring as each other. These markings will implicitly encourage people to focus on the interesting questions of how and when corners rotate and edges flip
 
 
Before I started writing this, I spent months and months carying one, and sometimes several cubes around with me. I loved watching and thinking about how the different edges and corners would travel around the cube in relationship to each other.
 
 
The basic idea of this model (below) 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)
 
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)
Line 15: Line 9:
 
down front position would be represented as (Left Down) (Down Right)
 
down front position would be represented as (Left Down) (Down Right)
 
(Front Front).
 
(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."[[1]] to have a better understanding of the Edged/Corners approach
   
 
<haskell>
 
<haskell>
Line 38: Line 36:
 
data Is = R|L|U|D|F|B
 
data Is = R|L|U|D|F|B
 
</haskell>
 
</haskell>
  +
  +
[[[1]] [http://www.cs.princeton.edu/courses/archive/fall06/cos402/papers/korfrubik.pdf]
   
 
[[Category:Code]]
 
[[Category:Code]]

Revision as of 22:48, 16 June 2010

Here is a simple model for a 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."1 to have a better understanding of the Edged/Corners approach

#!/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

[[[1]] [1]