Thinking Programmatically and the Rubik's Cube

Thinking Programmatically and the Rubik's Cube

First off, this is not a story of programatic buying, programatic ads, or any other automated web service. This is the story of how to break down tough coding or programming problems and how it relates to another of life's many mysteries, the Rubik's Cube.

As with any good article I'll delay the good stuff with a bit of a history lesson. But since this isn't really a story about that either here is the copy and pasted version from Wikipedia:

Rubik's Cube is a 3-D combination puzzle invented in 1974 by Hungarian sculptor and professor of architecture Ernő Rubik. Originally called the Magic Cube, the puzzle was licensed by Rubik to be sold by Ideal Toy Corp. in 1980 via businessman Tibor Laczi and Seven Towns founder Tom Kremer, and won the German Game of the Year special award for Best Puzzle that year.

So now the real story of how to solve one of these mystery cubes and how that leads in to thinking like a programmer. The Rubik's Cube, no matter what state it is currently in, is only about 3 minutes from completion if you know one secret about it. That secret is that the Rubik's cube is nothing but a mathematical puzzle, and there is no magic to solving it. You just need to learn the various 'forms' needed to get to the finish and the algorithms that make those happen.

Forms as Milestones

The forms of the Rubik's cube are nothing more than intermediate stages you need to get to from a completely scrambled cube to a completed one. They begin with The Cross, and then The Completed Face, The Middle Layer, The Top Cross, Top Corners, and then Top edges. After the last form is complete you have a completed cube.

The problem many people have is that looking at a scrambled cube you simply don't know where to begin unless you learn these forms ahead of time and the algorithms you need to utilize to get there. This is the same with the idea of programming something massive. You can know what the start looks like, and what the end is, but unless you set your forms that you need to hit up until the end you will only end up wasting lots of time and spins trying to jump from point A to point Z in a single bound.

Programatic Algorithms

Knowing what a Rubik's Cube needs to look like when it is done, and even every step along the way also will not make it easy to solve one of these cubes. It will more than likely look like it takes massive brainpower and a little bit of magic to make it actually work. After you have learned how, and solved one one time however you will see that to hit each form along the way is nothing magical, it's simply utilizing your knowledge to follow the algorithms to the solution. 

The algorithms are actually broken down into single turns of particular faces of the Rubik's Cube. Here is a section from the PDF guide available here to show you how to solve the cube: 

These discrete turns are nothing more than knowing how to manipulate the current code state to get closer to your next form. They are often written out as Ri,Di,R,D for short form ways of notating directions.

Increasing Speed and Efficiency Through Algorithms

The secret to solving a Rubik's Cube is only to learn how to solve a Rubik's Cube. There are dozens of guides out there, videos, articles, etc. This puzzle isn't a mystery any more. The secret to solving a Rubik's Cube quickly and efficiently is nothing more than memorization of more algorithms. Just like the best way to become more efficient in your programming is to know your language better. Read up on it, view screencasts, learn all the little tricks people have figured out.

The fastest solves on record are by those that have memorized over a hundred algorithms to speed the solving of the forms. I'm not saying to memorize every bit of a programming language, I'm saying the more you know it the more you realize you haven't memorized it, it has just become second nature.

There Is No Magic To It

The best advice I had ever been given when I was learning programming, and one that applied very well to the cube is that there is no magic involved here. It is a solid set of logical steps to reach the goal. For programming that means that no matter what a bug is, there is a source to it. There is a logical flaw somewhere. A computer, and thus a program will never just give you random magical issues.

This is also the same for cube solving. If you ever follow an algorithm, and the outcome is unexpected, it is because you more than likely messed up the algorithm or didn't follow a step correctly. The cube is not magic, it is a series of steps, nothing more and nothing less.

The Wrap Up

Now if you enjoyed that, check out this guide I linked earlier for solving a Rubik's Cube. You can also check out The Rubik's Cube Explorer to learn more about the cube and play with an interactive digital one. Happy programming and happy cubing.

Lastly, enjoy this video of a kid averaging a 14 second Rubik's Solve. Yes, he is using only one hand. 

 

To view or add a comment, sign in

Others also viewed

Explore content categories