# Generalised Rubik's cube algorithm to go from any valid cube state A to any valid cube state B.

For a $$3 \times 3 \times 3$$ cube, there are several known algorithms to go from any valid state of the cube to the solved state, $$S$$, of the cube (same color on each side).

How about a more general question: an algorithm to go from any valid starting state $$A$$ to any valid end state $$B$$

i.e. $$B \in \{$$ Set of all valid $$3 \times 3 \times 3$$ rubiks cube configs $$\} - \{A\}$$.

A trivial algorithm would be: go from $$A$$ to $$S$$ and then reverse the steps required to go from $$B$$ to $$S$$

However this algorithm is stupid. Can we do better?

• Are you familiar with group theory? It gives a nice way of thinking about the Rubik's cube and other such puzzles with reversible steps. Commented Jul 27, 2023 at 13:56
• It's not that stupid, in my opinion. It's the obvious solution, and it's slightly suboptimal. But it works just fine. Commented Jul 27, 2023 at 13:59
• Write down the moves of that trivial but non-optimal solution that takes you from A to S to B. Call this move sequence X. You want a shorter move sequence that does the same as what X does. So apply the reverse of X to a solved cube, and try to solve that directly. The move sequence you get is your answer. This is equivalent to Karl's solution. Commented Jul 27, 2023 at 15:34

Imagine repainting the cube in state $$B$$ to make it look like $$S$$, and keep track of how you paint each piece. Now apply these repaintings of the individual pieces to the cube in state $$A$$. This gives you a new cube state $$C$$. Apply the cube-solving algorithm to $$C$$; the steps that turn $$C$$ into $$S$$ will also turn $$A$$ into $$B$$.