A rigorous (and surprisingly involved) solution of this problem can now be found in the preprint available at arxiv.org/abs/2308.10321 which will appear in the American Mathematical Monthly. It is written with a broad mathematical audience in mind but I want to restate the core aspects using only minimal notation.
For this purpose, let me restate the problem. Identify each of the letters of the alphabet with their position, starting with zero, i.e., a <-> 0, b <-> 1,... Assume we are given a combination lock with n wheels numbered from left to right by 1,2,...,n and on each wheel the numbers from 0 to N-1=25 are printed. In each move we are allowed to turn an interval (a contiguous subsequence) of wheels, e.g. wheels numbered either upwards or downwards.
What is the minimal number of moves to get from an initial combination f = (f(1),...,f(n)) to a target combination g = (g(1),...,g(n))?
Here, f(i) is in [0,N] := {0,...,N} is the number chosen on the i-th wheel. By rotating both initial and target in advance, we can assume that g = (0,...,0). The optimal number of moves necessary to turn f into g can then be written in terms of the forward difference
Df(i) = f(i+1) - f(i) for i = 0,...,n,
where we extend f by setting f(0) = f(n+1) = 0. Let
D_+ = {i in [0,n]: Df(i) > 0} and D_- = {i in [0,n]: Df(i) < 0}
be the subsets where f has an upward/downward jump and enumerate them nonincreasingly according to the size of the jump, i.e.,
D_+ = {i_1,...,i_L} such that |Df(i_1)| >= ... >= |Df(i_L)|,
and
D_- = {j_1,...,j_M} such that |Df(j_1)| >= ... >= |Df(j_M)|,
where L is the length of D_+ and M is the length of D_-. Then the minimal number of moves is given by
A - B,
where
A = (1/2)*(|Df(0)| + |Df(1)| + ... + |Df(n)|)
and
B = max{(|Df(i_1)| + |Df(j_1)| - N), 0} + ... + max{(|Df(i_K)| + |Df(j_K)| - N), 0},
where K is the minimum of L and M. If L or M are equal to zero, then we set B = 0.
That is, the minimal number of moves is half of the total height of jumps in the combination, augmented by zeros at each end, minus some compensation which is given by pairs of large upward and downward jumps which in total exceed the 'height' N of the lock.
Consider for example a wildly varying combination such as f = (0,N-1,0,N-1,...,N-1) (which is extended to (0,0,N-1,0,N-1,...,N-1,0) ) and assume that n is even. Then the optimal way to turn it into the zero combination is to turn each of the N-1's upwards to a zero, taking n/2 moves. There are n/2 upward jumps of height N-1 and n/2 downward jumps of height N-1. The above formula gives A = (N-1)n/2 and for B=(n/2)(N-2) resulting in A-B=n/2. This is exactly the same as there are many large upward and downward jumps which 'cancel' each other.
On the other hand a monotone combination such as f = (0,1,2,3,4,...,25) (which is extended to (0,0,1,2,3,4,...,25,0) ) will have only one large downward jump of height 25 but no large upward jump to compensate it. Therefore, the total sum of jumps is 25+25 giving 25 as the least number of moves.
The proof of the formula for the optimal number of moves can be turned into an algorithm to give an optimal sequence of moves. In short, one shifts the combination at large jumps and then 'fills' it with blocks. Since the process is somewhat involved I refer to the above preprint for more explanation.
zzzzbzzzz
three moves? Can't you doaaaaaaaaa => zzzzzzzzz => zzzzbzzzz
(2 moves)? – Johnathanjohnathonz
goes back toa
first. – Phytologyz
tob
in one move, even if the wheel is alone? – Johnathanjohnathonabc
=>bcd
is one move. – Phytologyaaaaaaaaa
=>zzzzzzzzz
=>zzzzbzzzz
invalid? – Johnathanjohnathonaaaaaaaaa
=>zzzzzzzzz
=>zzzzazzzz
=>zzzzbzzzz
. – Phytologyzzzzzzzzz
=>zzzzazzzz
=>zzzzbzzzz
count as two separate steps? – Johnathanjohnathonalgorithm
, and, although its text was a bit confusing at the beginning, I do really think its current version is minimally well-stated to accept answers. – Cassius