The algorithmic trick that solves Rubik’s Cubes and breaks ciphers
What do the Rubik’s cube and a cipher from the 70s have in common? Let’s find out.
Our Patreon:
0:00 Rubik’s cube
9:40 DES
------------------------
Links:
Feliks setting the record
webpage “God’s number is 20“
The fact it was verified computationally that every cube can be solved in at most 20 moves is super impressive and much more complicated than the problem of solving just one cube that we covered in this video!
Four degrees of separation on Facebook
Code:
------------------------
Fill in the gaps:
Convince yourself that the meet in the middle algorithm finds the shortest path!
Convince yourself that the meet in the middle algorithm for Rubik’s cube does not need to know that every cube can be solved in 20 steps.
------------------------
Real Algorithms:
The first algorithms solving a random scramble like Korf’s algorithm
work roughly as follows:
First, although there are around 10^20 possible cube configurations, if you focus on just the possible configurations of 8 corner cubies, the number of possibilities drops to around 10^8. Using breadth first search, you can precompute for each such configuration of corner cubies how many steps you need to put them into the correct position. You need at least that many steps to solve the full cube configuration, probably even more as you need to solve not just the corners but also the edges.
You can now iterate a breadth first search from your scrambled cube, each time looking into further distance from it. For each cube you look up in your table of size 10^8 to find how many steps, at least, are needed to finish the search. If it is more than the current maximum distance you are looking at, you stop searching, as you can be sure you will not find the solved cube in this branch of the breadth first search.
This approach is similar to the meet in the middle algorithm in that we first precompute some information from the solved cube and then run breadth first search from the scrambled cube. However, now you need much less memory.
The actual state of the art algorithms are more complicated than that. You can read more about it e.g. here.
’s_Cube
------------------------
More Connections:
The meet in the middle trick is also called “bidirectional search“ in the context of searching graphs.
Computing the exact number of states of a Rubik’s cube (we used it is around 10^20) is not so hard.
The graphs where the number of nodes in your distance grows exponentially are pretty important in computer science. For example, there are scale-free networks and expander graphs.
Triple DES is kind of a hack made to prolong the life of the DES cipher when it became apparent that it is not strong enough. However, because of the meet in the middle attack, its “security level“ is only 2*56 bits and not 3*56 bits as one would naively expect. But you still need to apply DES three times. So you can guess it is not the most efficient way of doing the encryption; it is now superseded by the so-called AES standard.
------------------------
Riddles:
If you like to solve algorithmic puzzles, here you can find more algorithmic problems that can be solved with this technique:
Try to prove, just with pen, paper and calculator that there is a cube for which at least 16 moves are needed to solve it.
Try to convince yourself that by blind search of the cube graph you cannot beat the sqrt(N) time, at least if you do not use anything else than that the graph “looks random“. Hint: Birthday paradox
------------------------
Attributions:
To make this video, we used manim, a Python library:
The color palette we use:
Photo of Grant Sanderson:
Thumbnail: Alžběta Volhejnová