Solving the Rubik's Cube (with Math)
Most of you probably know that there are certain algorithms out there in the wild juggles of the internet or the vast plains of that sneaking little piece of paper that often comes with a new Rubik's Cube. But where do those algorithms come from? How did somebody come up with them in the first place? Trial and error? Probably in part... but you've surely found from experience that it would take a LOT of trial and error to come up with those algorithms if you had no other strategy. So, what do you do? That's where math comes in.
A Word on Algorithms and the Nature of Math
So first, a few words about algorithms in math. A lot of people think of math as just following a series of steps (algorithms) that their teacher told them until you get what you're supposed to. It makes sense that people think of it this way, because for many people, when they go to math class in middle and high school, that's what they do.
But there's a lot more to math than memorizing and following algorithms. In fact, some would argue that following a memorized algorithm isn't really math at all.... At the very least, it's not the cool part of math. Somebody who describes themself as a mathematician is not likely to be sitting around all day following predetermined algorithms that somebody handed them and said "Do this." If it were, there'd be very few mathematicians. Because that's boring...
BUT you know what is definitely math? Coming up with your own algorithms. What's the difference? Why is following algorithms not necessarily math, but creating algorithms is? While, there is no one perfect definition of math, many would agree that problem solving is an important part. Additionally, if you do try looking up a definition, common themes are that it studies structure, relationships, and pattern. So, if you are given a set of steps to follow, is that problem solving? Not really. You already have the steps, so where is the problem to solve? Additionally, simply executing a series of predetermined steps doesn't tell up that much about structure, relationships, or patterns.
On the other hand, creating an algorithm? Now there's a problem to solve. You have a goal. But you're not sure how to get there. It's an adventure! Or, better yet, a puzzle! And creating an algorithm involves identifying patterns. You must find relationships between what it's like before the algorithm and what it's like after. And you need to understand the structure so that you know when your algorithm can be used and when it can't.
And it doesn't have to be complicated either. Keep reading a little longer, and this page will guide you through creating your own algorithms!
Creating Rubik's Cube Algorithms
This section is going to walk you through creating your own algorithms for how to solve the Rubik's Cube. It's not going to tell you exactly how to do each part because figuring it out is part of the fun and is a lot more satisfying. Also, as mentioned in the previous section, creating that algorithm is the most mathematical part. However, this article will give you some guidance and suggestions to help you on your way.
You don't need any specific mathematical background for this part. Just an interest in Rubik's Cubes and a willingness to try things out and stick with it!
Okay, get out your Rubik's Cube (or use the applet below) and try this yourself. First, scramble the cube. I know. It's scary. But you can do it!
How to Use Applet
Rotate whole cube : Click on white space and drag
Rotate a face clockwise: Type the capitol letters corresponding to desired side into the algorithm box
Rotate a face counter-clockwise: Type the capitol letter corresponding to the desired side followed by an apostophe into the algorithm box
- F: Right face - Red in initial orientation
- R: Right face - Green in initial orientation
- U: Upper face - Yellow in initial orientation
- B: Back face - Orange in initial orientation, but not initially visible
- L: Left face - Blue in initial orientation, but not initially visible
- D: Down face - White in initial orientation, but not initially visible
- M: Layer between left and right faces
- E: Layer between upper and down faces
- S: Layer between front and back faces
To reset the cube: Click the double back arrow to the left of the algorithm box
Important note: When you click play, it will execute all commands in the algorithm box. This means that if you don't want a previous command to be repeated, you will need to delete anything in the algorithm box before entering your new command.
If prefered, the applet above can be opened in a new tab using this link.
Now, turn the cube so that the side with the yellow square in the center is facing up (which side is facing up doesn't really matter, but it will probably be easier to follow if everyone is turned the same way). Find a side piece (one with 2 colors) where one of the sides is yellow. Make note of where the yellow side is to start and write down each step you take from here. Find a way to move the yellow side so that it's facing up (on the same side as the yellow center).
Do you have your steps? If so, you just made your first algorithm! See, that wasn't so bad.
Now, the important part, when does your algorithm work? And when does it not? (Remember how math explores structure? That's what you're doing!)
Here's an example. A possible algorithm is "Turn the front 90 degrees clockwise." In which of the following situations would this algorithm work if your goal it to move the red-yellow side so that the yellow face is on top with the yellow center, and in which would it not? (Note: You may need to move the cube a bit to find the yellow-red side, but in all the images, the red-yellow side is on the front layer (with the red center). To do so, just click and drag on the white space around the cube. Try to avoid clicking and dragging on the cube itself or the faces may turn.)
Okay, so, you want to be able to move the yellow side to the top regardless of its starting position, so there are a couple of options now. You can either make the algorithm general enough that it can apply to multiple situations or you can make separate algorithms for each situation. It's your decision. An example of making it more general to apply to multiple situations would be the following:
General Algorithm:
1. Turn the cube so that the yellow center is on top, and the yellow side piece you want to move to the top is on the front layer (the layer closest to you), but the yellow sticker itself is not facing you. Refer to the image below:
2. Turn the layer closest to you until the yellow side lines up with the yellow center on top.
That more general algorithm can take care of all 3 cases from before.
Now, for an example of how to do it by using separate algorithms for different cases, let's look at the following. There will be one common step (the same as in the general algorithm) to get everyone's cube facing the same way, but then, it will split into 3 algorithms.
Common step:
1. Turn the cube so that the yellow center is on top, and the yellow side piece you want to move to the top is on the front layer (the layer closest to you), but the yellow sticker itself is not facing you. (Refer to the image in the general algorithm)
Algorithm 1 (for if the yellow side is on the left after completing the common step):
2. Turn the front 90 degrees to the right.
Algorithm 2 (for if the yellow side is on the right after completing the common step):
2. Turn the front 90 degrees to the left
Algorithm 3 (for if the yellow side is on the bottom after completing the common step):
2. Turn the front 180 degrees
Now, for this part of solving the cube, it might seem silly to separate the algorithms to separate conditions, but as you go on to develop more complicated algorithms, sometimes it can be clearer and easier to follow if you separate them by initial conditions. Other times, it's easier to keep it more general. There isn't one right way. It depends on your preference as the creator. The power is in your hands!
Okay, now that you have the idea, go ahead and make algorithms to complete the rest of the yellow face. It might take some time and experimentation, but you can do it!
At this point you might be thinking something like "Okay, but I could already do that part. What do I need these silly algorithms for? I just want to know how to do the bottom layer!"
If so, just hold on. You're closer than you think!
To complete the second layer, you can come up with algorithms by experimentation with a bit of spatial reasoning and pattern recognition. Or you can use the trick that you're about to learn for the third layer, and you can also find ways to apply it in the second layer. That part is up to you.
Now, for the third layer. There are many strategies that you can use to come up with algorithms, but the one used in this article is from a video that is linked here.
First, a quick word about inverses. In math, you may have heard about inverse functions or inverse operations. We can basically think about an inverse as something that "undoes" something else. For example, let's look at inverse operations. Let's say we start with 5. Now, add 3 and get 8. Well, the inverse operation of addition is subtraction, so subtract 3 from 8 and get back to 5. The subtraction "undid" the addition.
With functions, it's the same idea. In a function, you put something in and we have some rule for what comes out, and for each thing you put in, there's only 1 option for what comes out. It's like a vending machine. If you push the button on the vending machine for your favorite candy bar, you know that the only thing that is going to come out is the candy bar. You wouldn't want to have to wonder if you were going to get your candy bar or some weird crackers that you don't really like.
So, with inverse functions, you take input x and you put it through your original function and get some output y. Now, if you put y into your inverse function, you get back the x that you started with. The inverse function "undid" the original function. Now, keep in mind that x and y don't have to be numbers. They could be buttons on the vending machine and candy. They could be people and names. They can be whatever you want as long as every input only has 1 output.
Okay, but what do functions and inverses have to do with the Rubik's Cube? Well, an algorithm is really just a type of function. You have your starting input (in this case the starting state of our cube) and you follow your algorithm, and you get an output (the ending state of our cube). If you have the same starting state, following the steps of your algorithm will give you the same output every single time, so that meets our definition of a function. But, even better, all algorithms on the Rubik's Cube have inverses! Not all functions have inverses, which is something we can get into more another time, but with our Rubik's cube algorithms, finding an inverse is super easy! Just take each of your steps that you wrote down, start from the last step, and do the opposite. (For example, if the last step was to turn the front of the cube clockwise, then the first step of the inverse is to turn the front of the cube counterclockwise.) Then, move on to the second to last step, and so on. Pretty soon, you've undone the whole thing!
So, why should you care? Well, by this point, you've become pretty comfortable with the top layer, right? You have all your great algorithms. So, it shouldn't be too tricky to adjust some of your algorithms to, for example, swap the places of two pieces on top, right? You might not have it right now, but play around with it for a bit and use the algorithms you already made as a starting place, and pretty soon, you'll have an algorithm that can swap the places of two pieces on the top layer, while leaving all the other pieces on the top layer the same.
But now, the bottom is all messed up. Right? Not to worry! Just use your inverse algorithm like you just learned about and the bottom will be exactly how it started! But wait.... Now the top pieces are swapped back! So it didn't really do anything! What was the point of that?!
Well, what about if just before you use your inverse algorithm, you rotate the top layer! Nothing in the bottom 2 layers has changed, so when we do our inverse algorithm, they'll go right back to how they were before, but in the top layer, it will be different! How it's different will depend on which two pieces you choose to swap and how far you choose to rotate the top, but this gives you a strategy to create algorithms that will change things on one layer without changing things on the other 2 layers! You can do the same thing, but instead of swapping two pieces, you can create an algorithm the rotates one piece in the top layer (and then the inverse, after rotating the top, will rotate a second piece).
One final hint. If you're using the strategy above, notice that you'll always be doing things in pairs in any algorithm. Whether it's swapping two pieces and then swapping another pair in the adjusted inverse, or rotating a piece, and rotating another piece in the adjusted inverse. The moves will come in pairs. Remembering that will help you make your algorithms to solve the cube!
So, there you have it! All that's left is to keep working on it! It might take some time, but stick with it for a little while and you'll be able to solve the Rubik's Cube using only algorithms you made yourself!
Other Mathematical Extensions
There are numerous mathematical ideas related to the Rubik's cube beyond simply the creation of algorithms. However, due to limitations on time, it's impossible to explore all of them fully. Therefore, this section will provide links to other resources that can used to continue to delve into the mathematics of the Rubik's Cube for those who are interested.
Group Theory
Group theory in math studies sets of objects and the things that we can do to those objects (operations). This can be used in Rubik's cubes to look at different combinations of moves and how they affect the configuration of the cube. This can help create algorithms and techniques for solving it.
- A Mathematical Approach to Solving the Rubik's Cube – This is a short article that provides a very brief introduction to using group theory to solve the Rubik's Cube. It's written in a way that it can be understood by people without a lot of mathematical background, but it also doesn't go into a lot of detail.
- The Mathematics of the Rubik's Cube – This is a detailed discussion of group theory and its applications to solving Rubik's cubes. It's a bit more technical and would likely be best for somebody with a bit more background in math.
- Mathematical Understandings Of A Rubik's Cube – This is a good in between source. It still goes into quite a bit of detail about group theory and it's applications to solving the Rubik's Cube, but it's written by an undergraduate student and makes more of an effort to explain unfamiliar terms.
Using Rubik's Cubes in Teaching
These resources focus on potential ways to include Rubik's Cubes in the general grade school math curriculum. They are not necessarily as focused on the mathematics of how to solve the cube, but rather on other ways that using Rubik's cubes can help students develop further understanding of other topics. Some are focused on specifically how to use the Rubik's cube in teaching and others are simply resources that could be shared with students to increase interested in certain high school level math topics by providing connections to Rubik's Cubes
- Using Rubik's Cubes to Teach Math in High School – This article is primarily focused on the potential of Rubik's cubes to increase engagement and interest in a mathematics classroom. It gives several simple examples of how to incorporate fascinating puzzles to explore topics such as percentages, fractions, rate of completion, and factorials.
- Why Are There 43,252,003,274,489,856,000 Rubik's Cube Combinations? – This video would be a great addition to a unit of combinations and permutations. It explains how to find the number of possible Rubik's cube configurations
- Teaching Math Through Solving Rubik's Cubes – This article is focused on general skills and attitudes important to mathematics that can be developed through learning to solve a Rubik's Cube. Some such attitudes include growth mindset, perseverance in problem solving, and willingness to accept and work through discomfort