user1277399
user1277399

Reputation: 81

How to represent a Rubik's cube

I want to know how we can design a rubics cube in mathematica .Is it possible and how can we go with it. how can we decide the different separation of the smaller cubes on the 6 faces of the cube .

Upvotes: 4

Views: 1062

Answers (1)

ninjagecko
ninjagecko

Reputation: 91122

You are asking how to define a data structure. Your choices is arbitrary, as long as the operations you define work correctly. For example you could represent a cube like:

newCube[] := {
    {red, red, red, red, red, red, red, red, red},
    {orange, orange, orange, orange, orange, orange, orange, orange, orange},
    {yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow},
    {green, green, green, green, green, green, green, green, green},
    {indigo, indigo, indigo, indigo, indigo, indigo, indigo, indigo, indigo},
    {purple, purple, purple, purple, purple, purple, purple, purple, purple}
}

Then you can either define a twist (and optionally anti-twist) operation, one for each move (3 axes, 3 layers to twist per axis, 2 directions to twist; alternatively 6 axes, 3 layers to twist per axis), or two rotate operations and a twist, and assume you can compose these to generate effects like inverseRotate[simpleTwist[rotate[cube], ...], ...].

To figure out the code you need, you have to have a map from your representation to the real object. Perhaps it would be better to demonstrate an example for a coin, which is either heads or tails:

newCoin[] := {heads}

flipCoin[coin_] := {If[coin[[0]]==heads, tails, heads]}

This can be more complicated if it's not easy to represent your object with basic data structures, like lists. You could even represent your cube with matrices like:

newCube[] := {
    /red, red, red\  /orange, orange, orange\
    |red, red, red|  |orange, orange, orange|
    \red, red, red/, \orange, orange, orange/, ...
}

But the way the matrices are stitched together can't easily be represented. So their ordering in the list is arbitrary.

If you are still confused, you can do this:

Give each slot in your representation an arbitrary number (worst-case, you label them 0 through 53, but you can be more elegant about it). Then with a real Rubik's cube, write those numbers on each face. Then when you do an operation, write down their new positions. This is called a permutation that that particular allowed move/twist induces on your semigroup data structure. As mentioned earlier, there are quite a few of these (18), and you have to write them all down. Then you can have something like:

newCube[] := {0,1,2, 3,4,5, 6,7,8, ...53}

permutations = {
    {12,15,0, 3,4,5, 6,7,8, ...},  (*figure these out yourself*)
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . },
    {. . . }
}

twistCube[cube_, moveNumber_] := Permute[
    cube, 
    FindPermutation[permutations[[moveNumber]]]
]

You can optimize this with computer science tricks like rather than calling FindPermutation each time, making permutations = FindPermutation /@ {...}

Upvotes: 6

Related Questions