DEV Community

Cover image for Moving one piece without undoing the rest
Israel Negrete Lepe
Israel Negrete Lepe

Posted on Originally published at crtdrops.mx

Moving one piece without undoing the rest

I have had cubes for as long as I can remember. I am the youngest of my siblings. I solved my first cube by myself, with no guide, and it took me months.

I never timed myself, and it has been a long time since I solved one all the way. Today I keep them at the office and at home: more than ten 2 × 2s, plus 3 × 3 and 4 × 4 cubes, a triangular one and even keychain cubes. I turn them to let off stress, turning and turning pieces. For me the challenge is not solving it. The challenge is moving pieces into position.

When I do solve one, I go layer by layer: one face as the base, then the middle layer, and work my way up. I don't like the method that does one face and then the corners.

The math came to me by another road: I studied electronics engineering, and there you chew on math. Solving a cube is not just about every face being one color. It is about transforming a system while respecting rules you can't always see.

What no turn can do

A 3 × 3 cube has 26 visible pieces: 6 centers, which don't move relative to each other; 8 corners, with three colors, and 12 edges, with two. If you take it apart and put the pieces back any way you like, there are 519,024,039,293,878,272,000 ways to arrange them. With turns, starting from a solved cube, you can reach only 43,252,003,274,489,856,000: one in twelve.

The other eleven are ruled out by three laws that no turn breaks:

  • Corner twist. Each corner can be twisted a third of a turn one way or the other; counted with a fixed rule, the twists of all eight always add up to a multiple of three. A single corner twisted in place, with everything else solved, cannot be solved.
  • Edge flip. Counted with a fixed rule, the number of flipped edges is always even. A single flipped edge cannot be solved.
  • Parity. Every quarter turn moves four corners in a cycle and four edges in a cycle, at the same time. A cycle of four is the same as three swaps; every turn adds an odd number of swaps to the corners and to the edges at once, so the two always stay in step: if two corners trade places, two edges do too. That is why you never end up with just two pieces swapped.

Each law rules out a share: the corner law, two arrangements in three; the edge law, half of what is left; and parity, another half. 3 × 2 × 2 = 12. So when a cube can't be finished no matter how hard you try, it is not always lack of skill: it can be a state that turns could never produce. Someone took it apart and put it back differently, or peeled and swapped stickers. Math does not only help you find solutions: it also proves when a solution is impossible.

Moving without undoing

That is my challenge, and that is where the laws show. Moving a piece where you want it is easy; the hard part is moving it without undoing what was already right.

That is what sequences that move a few pieces and leave all the others in place are for. The workshop tool uses two of them at the end of its step-by-step solution:

  • R' F R' B2 R F' R' B2 R2: 9 moves that cycle three corners. The other 17 moving pieces (the centers don't count) end up as they were.
  • R U' R U R U R U' R' U' R2: 11 moves that cycle three edges. The other 17 pieces also end up as they were.

Both move three pieces, not two, and that is no accident: because of parity, there is no sequence that swaps just two corners, or just two edges, and leaves everything else the same. The least you can do to move pieces of a single kind to other places is a cycle of three. Twisting two corners or flipping two edges in place is possible, but that does not move them to other places.

And a curiosity for anyone who, like me, turns for the sake of turning: any sequence, repeated enough times, brings the cube back to where it started. R U R' U' repeated six times leaves it exactly as it was; the tool checks this in its tests.

How many moves it takes

It is known that any 3 × 3 cube can be solved in 20 moves or fewer, counting a half turn as one. Tomas Rokicki, Herbert Kociemba, Morley Davidson and John Dethridge proved it in July 2010, with about 35 CPU-years of spare computer time donated by Google (cube20.org). Counting only quarter turns, the number is 26 (Rokicki and Davidson, 2014; cube20.org/qtm).

That does not mean a person solves it in 20. The tool gives two solutions for the same cube. In its tests, with 100 scrambled cubes:

  • The short one, with the two-phase algorithm: about 20 moves on average (20.1 in its tests; the search stops on a time limit, so it varies a little with the speed of the machine), between 18 and 22. It does not guarantee the shortest.
  • The one a person would follow, step by step: cross, bottom corners, second layer, top cross and the top corners and edges. 129.4 moves on average, between 76 and 165. It is longer, but every step has a reason you can learn.

And 2 × 2s, of which I have more than ten, have 3,674,160 possible states, counting as one the states that only look different because you turned the whole cube in your hand.

What it has in common with work

I don't have an anecdote that ties it to my work, and I am not going to make one up. But the way of thinking is the same: identify the starting state, understand the constraints, split the problem and apply transformations that don't destroy what already works. And accept that some states can't be reached, however hard you try, because the rules don't allow it.

Cubes, for me, are something I enjoy. They are not a productivity method.

Try it with your cube

To find out whether your cube can be solved and how, there is From the state to the solution: it runs in the browser and sends nothing. You enter your cube face by face and it checks that every piece exists; if one of the three laws fails, it tells you which one and what may have happened (a piece popped out and put back twisted or flipped, the cube reassembled differently, or a square entered wrong). If the cube can be solved, it gives you the short solution and the one a person would follow, step by step. The code is on GitHub.

Your turn

When you pick up a cube, do you solve it, or do you just turn it? And have you ever had one you could never finish, and found out it had been put back together wrong?

Israel Negrete Lepe is an electronics engineer. Twenty-five years making different systems work together under real conditions: from the sensor, the vehicle or the transaction to the backend, the data, security and operations. Today, increasingly, edge AI. I take on projects by the hour or by deliverable: israel0negrete@gmail.com.

I send a short email when a new note or lab result comes out: subscribe here.

Top comments (2)

Collapse
 
svitlana_manicheva_4329af profile image
Svitlana Manicheva •

The "one in twelve" breakdown is the clearest version of that argument I've read, three laws and each one takes its share. Curious about the 129-move human method: which stage swings the most between 76 and 165, the second layer or the last-layer steps?

Collapse
 
crtdrops profile image
Israel Negrete Lepe •

Neither one on its own, which I didn't expect. I reran the 100 test cubes and split the moves by stage.

Per stage, the widest swings are the bottom corners (18 to 57 moves) and the second layer (16 to 59). But each of the four last-layer steps can take zero moves when it happens to be done already, or up to 18 to 23, so together they carry a bit more of the spread: about 54% of the variance of the total, against 47% for the bottom corners and the second layer combined. The cross barely moves (4 to 12).

The 76-move cube got lucky on top: its last step took one move. The 165-move one paid in the corners (47) and the second layer (42).