How Many Times Until the Cube Comes Home
Do the sexy move — R U R’ U’, the first trigger every cuber drills — six times in a row and the cube snaps back to exactly where it started. No solving, no thinking, just the same four turns repeated until the scramble undoes itself. The first time I saw that, I assumed it was a quirk of that particular move. It isn’t. Every sequence of turns has a number baked into it: how many repetitions send the cube home.
That number is the order of a permutation, and you can compute it without touching a cube.
Model a set of pieces as a list where slot i records where piece i lands. One turn is a permutation. Repeating the turn is composing that permutation with itself, and composition is nothing fancier than indexing — to apply p twice, look up p at each of p’s own outputs.
# A permutation on n points as a vector: p[i] = where point i lands
compose <- function(a, b) a[b] # apply b, then a
order_of <- function(p) {
id <- seq_along(p); q <- p; k <- 1
while (!all(q == id)) { q <- compose(p, q); k <- k + 1 }
k
}
# (1 2)(3 4 5): a two-cycle stacked on a three-cycle
sexy <- c(2, 1, 4, 5, 3, 6)
cat("Order:", order_of(sexy), "\n")
In R the composition collapses to a single character — a[b] — because subscripting a vector by another vector is exactly “follow the arrows twice.” Keep composing until the list reads 1, 2, 3, … again, and count the steps.
Pascal, from the decade when kids were prying stickers off cubes to fake a solve, makes the same machinery explicit:
program CubeOrder;
const N = 6;
type Perm = array[1..N] of integer;
var sexy, q, id: Perm;
i, k: integer;
function Same(a, b: Perm): boolean;
var i: integer;
begin
Same := true;
for i := 1 to N do if a[i] <> b[i] then Same := false;
end;
begin
{ (1 2)(3 4 5): order lcm(2,3) = 6 }
sexy[1]:=2; sexy[2]:=1; sexy[3]:=4; sexy[4]:=5; sexy[5]:=3; sexy[6]:=6;
for i := 1 to N do begin id[i] := i; q[i] := sexy[i] end;
k := 1;
while not Same(q, id) do begin
for i := 1 to N do q[i] := sexy[q[i]]; { compose sexy with itself }
k := k + 1
end;
writeln('Order: ', k)
end.
Both print 6. The permutation I used, (1 2)(3 4 5), swaps a pair and rotates a trio, so it only comes home when both cycles finish together — at the least common multiple of 2 and 3. That’s the shortcut for reading an algorithm’s order by eye: break the move into disjoint cycles, take the lcm of their lengths. R U R’ U’ decomposes into cycles that also lcm to six, which is why the drill lands you back at solved.
Longer algorithms hide bigger numbers. Some corner-twisting sequences don’t return for over a thousand repetitions — a deeply unfun way to spend an afternoon, and exactly the kind of thing you’d rather ask an array than your wrists.