Algorithms IRL: Let’s solve a Rubik’s cube!

A few months ago my son asked how you solve a Rubik’s cube. I had no idea so we looked it up. A helpful YouTube video from The Great Courses showed us how to solve one in 8 steps. It took a few watches and lots of back and forth, but we did it! And despite my initial feeling that I’d never remember this process without following along every time, it wasn’t actually too hard to get the recipe memorised.

Want to give it a try? You can watch that video, and I’ve made a handy printable guide to help prompt you with the steps.

I’m fascinated that a puzzle that seems so difficult to work out has such straightforward ways to solve it, and it’s been interesting to look into more of the logic behind it and amazing solving feats that people are able to achieve. I’ve blogged previously about computer algorithms and how to think about evaluations and trade-offs with them (see pathfinding, advice from a Quake developer, and the magic of dynamic programming), and I can see a lot of parallels with this in-real-life algorithm challenge.

Understanding the problem

Photo of a disassembled cube. The 6 centre squares are all attached to a cross piece with 6 short arms. The other colourful pieces are scattered behind it. There's a screwdriver handle in the background.
No cubes were harmed in the making of this blog post; they come apart neatly after loosening with a screwdriver

These puzzles were invented in 1974 by Hungarian Ernő Rubik while he was a professor of architecture, and was interested in making a 3D structure whose individual pieces could move relative to each other while maintaining the same overall shape. He built it with wooden blocks and rubber bands, and marked colours on the faces to watch where they moved to. After twisting it a few times, he tried to “simply” put it back to its initial state and found himself absolutely stumped — it took him a month to work out how to solve this puzzle.

It’s gone on to huge international success: well over 500 million have been sold, making it the world’s best selling puzzle and possibly the best selling toy as well. Like many people I’ve played with quite a few over the years but never sat down and thought much about how they work.

A few facts that helped me visualise the problem: while it looks like you’re trying to move all 9 squares of each of the 6 colours onto a side each (making 9 * 6 = 54 moving parts), there’s quite a few more constraints.

The 6 centre squares are fixed relative to each other (see that cross piece that makes up the core of the cube?). The squares can spin in place, but:

  • Yellow is always on the opposite side of the cube to white (or, pick any pair of opposites — they’ll stay that way).
  • If you look down from above yellow, other sides are in a fixed order: red always has blue to the right of it, and carrying on you’ll find orange, then green, like fixed compass directions.
  • When you’re looking at a face of the cube with a yellow centre square, that is the yellow face — and solving the cube requires moving all the other yellow squares onto that face. If you gather yellows somewhere else you can’t send the centre round there.
The same disassembled cube as before, more neatly arranged. There are 3 groups of 4 edge pieces (2 colours each), and 2 groups of 4 corner pieces (3 colours each).
Cube’s core with 6 fixed centre squares, then the 20 moving pieces.

Apart from these fixed centres, there are two kinds of moving pieces:

  • Edge pieces have 2 colours on them. There are 4 edge pieces on each layer of the cube. Each edge piece has exactly one place it can go — for example, at the top of the photo above there’s one that has yellow and blue on it. That needs to go in between the yellow and blue centre squares, it won’t work anywhere else.
  • Corner pieces have 3 colours on them. There are 4 corner pieces round the top layer of the cube, and 4 round the bottom. Like edge pieces, each of these has exactly one place it can go if you want to have a solved cube.

I had never thought about any of this in many years of occasionally having a go with a Rubik’s cube. It’s not a challenge of moving 54 squares around, it’s about just 20 moving pieces (12 edges and 8 corners), each with just one correct place to be. That sounds simpler, right?

Turns out there’s still room for complication: the total number of ways a cube can be scrambled is 43,252,003,274,489,856,000. That’s over 43 quintillion, a number that’s hard to imagine. Wikipedia helpfully says that if you had one cube in every possible scramble, those cubes would be enough to cover the surface of the Earth 275 times. And somehow, if you learn that 8-step recipe, you could be handed any one of the 43 quintillion possible cubes and solve it. That’s amazing.

Evaluating an algorithm

To decide what makes a “good” algorithm, you have to decide what you’re optimising for. This method I’ve learned:

  • Can be remembered: I was impressed how quickly my hands learned the confusing strings of movements. It became trickier when I decided to try teaching others — have you ever thought about your PIN number, and felt your hands go “oh, are you doing this?” then found you lost the ability to do it for 5 minutes? Reminds me of The Inner Game of Tennis, an excellent book for learning all sorts of skills.
  • Makes it easy to see progress: You solve the bottom layer, then the next, and see the cube “filling up” like a power bar as you work through the steps. It’s immediately obvious when you make a mistake, as you find one of the solved pieces suddenly popping up where it shouldn’t.
  • Is fast: While “solving it at all” was my goal, if I needed to sit for a whole month every time that’d be disappointing. After lots of solves (this is a very satisfying fidget toy), it took me about 90 seconds every time.
Photo of me holding a larger than usual cube (it's bigger than my head). I'm a 47 year old white man with short brown hair, glasses, wearing a zippy blue top and jeans.
Teaching others at Agile in the Ether IRL: Some might say I was mostly looking for an excuse to buy this comedy oversized instructor’s cube.

This is all pretty good, but how hard is it to solve the cube faster than that? Current record (set in Feb 2026): 9 year old Teodor Zajder with 2.76 seconds. Robots can do even faster times: record is a blink-and-you’ll-miss-it 0.103 seconds.

Give yourself less to do

One way to get faster is to give yourself less to do: That 8-step method takes about 110 face turns. That’s because it has few special cases (e.g. in the later steps, when you want to get all the yellows on the top facing up, you just keep repeating the same sequence of moves to shuffle them and eventually you’ll get there). For decades, researchers looked for “God’s Number” for Rubik’s cubes: if you were an all-knowing deity and could immediately see the fewest turns needed to solve a cube, what’s the most turns you’d ever need? We now know that God’s Number is 20.

However, if you’re a human going for speed, stopping to work out the absolute fewest turns for the particular scramble you’re handed seems unworkable. There is an event where competitors get the same scramble and all have an hour to write down the shortest solve they can work out, but for the speed cubing event people tend to use 50 to 60 turns. This reminds me of pathfinding advice, where you can spend more time setting up a clever algorithm than you would have spent just powering ahead with something simpler.

A very nice feature of this intro method I’ve learned: it’s a simplified version of the CFOP method, popularized by Jessica Fridrich and now the most common method used by those record-setting speedcubers. This means I can learn the trickier additions in any order I want, falling back to versions I know already when I’m not confident, rather than starting from scratch. There’s a staggering list of last layer patterns to recognise, great to know I can learn a few at a time.

Understand where the time goes

Advice from Quake is useful here: up there I assumed fewer turns means solving faster. Looking into tutorials I see some other ideas matter more:

  • Rotating the cube around so a different face is pointing at you is incredibly slow. It feels fairly quick to me, but if you were solving the whole thing in 3 seconds there’s just no time for this.
  • Changing your grip at all takes time, so you should think about how to avoid that. You can practice the “home grip” that lets you spin various faces with different fingers, and different tricks to string moves together smoothly with minimal regripping.
  • Some short sequences (e.g. 4 turns in a certain order) come up again and again — you can train these “triggers” so your fingers fly through them.

All of the above can lead you to prefer some longer sequences even when fewer-turn ones achieve the same result. If you can avoid turning the back face (awkward from the home grip you want to be in for most moves), or can use a well-trained 4-move trigger instead of 2 moves that are trickier to string together, it may be a better choice.

Throw hardware at the problem

This came as a surprise to me: Rubik’s-brand cubes are never used in competitions, or in any of the many tutorial videos I’ve watched. Despite being the original, since about 2007 there’s been an explosion of competitors with ever-fancier features for speedcubing and Rubik’s don’t seem to have done much in this area.

A video explanation of why Rubik’s brand cubes are “bad” describes things well — Rubik’s own cube is slow to turn and you can hear the springs creak. Alternatives from Gan, MoYu, and other Chinese companies start at prices much cheaper than Rubik’s and you’ll immediately notice the smoother turns and more forgiving self-alignment when you don’t get things precisely in place.

These cubes usually come with removable centre caps so you can adjust the tightness — from firm like Rubik’s original, through to spinning like a top with one finger flick. Some models use magnets and allow for amazing corner-cutting — so you can start the side turning after your top turn is just past 45 degrees and it all snaps into shape pleasingly. Some use “maglev” — repelling magnets — instead of springs in the core, and online there’s more info than you ever wanted to know about the benefits of springs vs maglev. All this is available in a £15 cube.

You can spend lots more if you like. But just like with computer algorithms, where you might turn to fancier laptops or paying lots for more cloud computing power, I think you won’t get huge benefit from investing much in this side of things until all the other things we’ve talked about are in a good place. If you’re a beginner you’ll spend more time looking at the cube and thinking about what to move.

If you do get near that 0.103 second robot world record, you may need to think about bespoke cube builds … apparently not ripping the cube apart is the hardest part, they had to redesign the core and centre pieces.

Photo of one big cube and a about 25 little ones haphazardly arranged in front and on top of it.
Standard size, perfectly usable cubes for £1.75 each when I ordered 20 of them. Great big one was £36, totally worth it.

Tempted?

If this post does prompt you to start learning cube solving, let me know! I’m sticking with this hobby, won’t set world records but I bet I’ll get much better than Current Neil.


Posted

in

by

Tags: