
The Mathematics of the Rubik’s Cube (2009) [pdf] - lainon
https://web.mit.edu/sp.268/www/rubik.pdf
======
perfect_wave
I've been fascinated by the Rubik's cube for years after learning to solve one
in 7th grade. I started to get back into it high school and dropped my solve
times down below a minute. Then I continued in college and got down to 25
seconds average with a personal best of 15.15.

I created a 2x2 Rubik's cube in Java as my freshman final project for my
second computer science class, but it was quite ugly.

Recently, I decided to take another look at implementing the cube - this time
using Python. I also wanted a way to generate cubes and check if they were
valid. The main representation of the cube is as a permutation group - a
48-tuple where each element in the tuple is unique. The solved cube is
represented as (0, 1, ... , 46, 47).

Turns of the cube simply permute this tuple. To figure these all out I spent a
lot of time with a cube covered in post it notes.

All of the stuff I implemented in the checking for valid cube comes from this
stackoverflow post: [https://math.stackexchange.com/questions/127577/how-to-
tell-...](https://math.stackexchange.com/questions/127577/how-to-tell-if-a-
rubiks-cube-is-solvable/127627)

I've had a lot of fun working with this cube as my personal project. I
recently created a Django website and a RESTful API to display randomly
generated cubes. Soon I'll be working on a data pipeline to process these
random cubes and display them nicely.

I've looked into working on a solution algorithm to implement Thistlethwaite's
algorithm -
[https://www.jaapsch.net/puzzles/thistle.htm](https://www.jaapsch.net/puzzles/thistle.htm).
I think this will take me a while, but it should be doable. I haven't really
though too much about implementing it, but I think the way to do it is to
define what it is for each step to be completed and then BFS a graph of moves
to end up in that state. If anyone has looked into this I'd love some advice!

You can find the code I've written on Github:
[https://github.com/elliotmartin/RubikLite/blob/master/Rubik....](https://github.com/elliotmartin/RubikLite/blob/master/Rubik.py)

~~~
Retric
My only suggestion is trying to quickly validate a cube is solvable seems like
a waste of time vs generating them via a large number of random rotations.
Especially when no cube can be more than 20 rotations from a solution.

~~~
perfect_wave
Some positions are far, far more common than others. So generating a cube by a
random string of rotations biases towards these positions. Take a look at the
count of positions table in the bottom right corner of this page:
[http://www.cube20.org/](http://www.cube20.org/)

Plus figuring out how to implement the various ways of checking validity was a
lot of fun.

~~~
Retric
That’s a different problem. If you want to check every possibly you don’t want
a randomized cube. You want the full list.

~~~
perfect_wave
I don't think generating every possibility of a cube is reasonably doable -
it's over 43 quintillion - 10^16

Edit: I think you simply didn't understand what I was talking about. The
distribution of states is not even. If you randomly perform moves on a cube
then you're more likely to end up in certain states.

~~~
Retric
For scale, fastest supercomputer is over 1.8 x 10^17 operations a second. So
generating 10^16 numbers is not that bad for a distributed project over a few
weeks.

As to the distribution of states, I am not sure what you mean. Insufficient
shuffling can introduce bias, but that gets reduced as you continue shuffling.
You can trivially shuffle past the point where remaining bias is not
detectable. Unless, you want a specific bias, then that’s more easily achieved
generating a random number with a specific format.

------
tuckermi
Is there a properly colorized version of this PDF floating around somewhere?
In particular, I'm wondering about this line that lies above a grayscale
image:

    
    
      For example, in the picture below, the red square is at FUR, yellow at RUF, blue at URF, and green at ULB

------
foxes
Mathologer has a nice video explaining how to solve a cube, and they are
really using group theory :),

[https://youtu.be/-NL76uQOpI0](https://youtu.be/-NL76uQOpI0).

The key take away is that all you need to do is find a few basic operations
(swapping an edge/corner/center) that leaves the rest of the cube unchanged,
and then your job is basically done, you apply these until you have a solved
cube.

This might approach might not give you the optimal algorithm, which has been
shown to be able to solve any Rubik's Cube in 20 turns or less [0].

[0] [http://www.cube20.org/](http://www.cube20.org/)

------
stilldavid
[https://cube20.org/](https://cube20.org/)

------
magoghm
There are also these much older (1980) notes on the Rubik's cube:
[https://maths-people.anu.edu.au/~burkej/cube/singmaster.pdf](https://maths-
people.anu.edu.au/~burkej/cube/singmaster.pdf)

------
maxxxxx
I really wish I had the brains to do math to figure out things like the
Rubik's cube. I find it fascinating how you can model something like this and
express it with math.

~~~
ssewell
Not sure if you're referring to cube theory or just the ability to solve... If
it's the former, almost anyone can learn to solve a Rubik's cube in a few days
(albeit in a non-optimal fashion). It's a matter of learning a handful of
algorithms for each layer then executing. It can quite a fun way to keep the
hands busy while thinking, like crocheting or knitting.

~~~
maxxxxx
I am talking about cube theory. Solving it isn’t that hard unless you want to
be super efficient. But formalizing it in way you can then reason about seems
very hard to me.

~~~
aidos
Is solving it not that hard?! I chipped away at it for a year before I figured
out a (really inefficient) technique.

~~~
maxxxxx
I remember after a few weeks I figured out a move that could swap two pieces
without other changes or something like that (don't remember the details). It
was horribly inefficient but it did the job.

------
alejohausner
Nice introduction to group theory. I wish my math profs had used some of this
material.

~~~
tzs
I was a second year undergraduate math major at Caltech when the Rubik's Cube
came out in the United States, and they quickly seemed to be all over campus.

Second year was when we took the intro to abstract algebra course. One of the
requirements my professor had was that we each had to do a term project
involving material from the class. I couldn't think if anything interesting,
so went to to see the professor to see if he had any suggestions for
interesting project areas.

He simply said "The answer is in your hands". I looked at my hands, and
realized I had been carrying my cube with me. Oops. I hadn't even figured out
how to solve the stupid thing yet, let alone understand anything mathematical
about it, and now my grade would depend on understanding it? DoH!

One of the first people at Caltech to figure out how to solve it was Peter
Shor. Until there were a fair number of other people who had figured it out,
Peter was nice enough to make a nightly circuit of the student houses solving
people's cubes for them.

I remember one strange night when Peter came around right as several of us
where wondering if some particular thing was reasonably do-able. The group
wondering this also happened to be high on LSD at the time. (To be clear,
Peter was not tripping. He just encountered the tripping group on his nightly
cube solving circuit).

Both Peter and one of the tripping people started working on the problem. The
strange thing was that the tripping person was not a theory guy. He was a
strictly experimental cubist. But for some reason he was just staring at his
cube thinking about the problem.

And Peter, who would usually figure out these things with theory instead was
just furiously trying things.

Peter and the tripping guy both solved it at the same time, while the rest of
us wondered if we had entered the Twilight Zone.

------
ensconced
dogschool.tripod.com

