# Fully Solving the Gear Shift Using Mod Integer Equations



## qwr (Jul 15, 2020)

For notation, hold the cube with white on top and green on front, like on WCA scrambles. Basically there are two kinds of gears: small 5-tooth gears and big 8-tooth gears. Turning one gear by 1 tooth turns the other gear the opposite direction by 1 tooth. Each turn can be represented by how many teeth clockwise it turns. Obviously turning the 5-tooth gear by 5 teeth returns it to its original position, and turning the 8-tooth gear by 8 teeth returns it to its original position. Notice 5 and 8 are coprime so turning any set of gears by 40 teeth returns them to their original position.

Each corner is labeled: x1 = UBL, x2 = UBR, x3 = UFR, x4 = UFL, x5 = DFL, x6 = DFR, x7 = DBR, x8 = DBL. (sorry if this is confusing.)
There are 6 moves, corresponding to each of the 6 faces. Each face move can be done by splitting the cube and turning the small gear clockwise or big gear counterclockwise. So U2 means split cube U/B and turn little gear clockwise 2 teeth.

Using this notation, we see U move affects x1 by 1, x2 by -1, x3 by 1, x4 by -1. Similarly for all other faces.

Knowing all this, we can write the integer equations in modular arithmetic needed to solve. In Mathematica:


```
Solve[
 x1 + u + l + b == 5 k1 &&
  x2 - u - r - b == 8 k2 &&
  x3 + u + r + f == 5 k3 &&
  x4 - u - l - f == 8 k4 &&
  x5 + d + l + f == 5 k5 &&
  x6 - d - r - f == 8 k6 &&
  x7 + d + r + b == 5 k7 &&
  x8 - d - l - b == 8 k8,
 {k1, k2, k3, k4, k5, k6, k7, k8, u, d, l, r, f, b},
 Integers]
```



Spoiler: Full solution



All variables are integers mod 40
x1 = c1
x2 = c2
x3 = c3
x4 = c4
x5 = c5
x6 = c6
x7 = c7
x8 = c2 + c4 + c6 + 2 c8
u = c13
d = -12 c1 - 20 c2 - 32 c3 - 20 c4 - 8 c5 + 25 c6 - 8 c7 - 35 c8 - 20 c9 + c13
l = c14
r = -12 c1 - 20 c2 - 8 c3 - 5 c4 - 32 c5 - 8 c7 - 5 c8 - 20 c9 + c14
f = 32 c1 + 32 c3 + 25 c4 + 32 c5 + 8 c7 - c13 - c14
b = 4 c1 + 5 c2 + 5 c4 + 5 c8 + 20 c9 - c13 - c14

c8 through c14 are free variables so we can set them to zero. If I did my math right, this simplifies to
x1 = c1
x2 = c2
x3 = c3
x4 = c4
x5 = c5
x6 = c6
x7 = c7
x8 = c2 + c4 + c6
u = 0
d = -12 c1 - 20 c2 - 32 c3 - 20 c4 - 8 c5 + 25 c6 - 8 c7
l = 0
r = -12 c1 - 20 c2 - 8 c3 - 5 c4 - 32 c5 - 8 c7
f = 32 c1 + 32 c3 + 25 c4 + 32 c5 + 8 c7
b = 4 c1 + 5 c2 + 5 c4



Yes I tested this, using `FindInstance` in place of `Solve`. But this assumes you start with a fully scrambled puzzle. It's pretty easy to solve the yellow face by splitting L/R and spinning each side until the bottom yellow face is fully solved. Then split F/B and spin F until two front corners x3 and x4 are solved. That leaves only two back corners, x1 and x2 unsolved, reducing the number of unknowns in the equations.


```
Solve[
 x1 + u + l + b == 5 k1 &&
  x2 - u - r - b == 8 k2 &&
  u + r + f == 5 k3 &&
  -u - l - f == 8 k4 &&  
  d + l + f == 5 k5 &&
  -d - r - f == 8 k6 &&
  d + r + b == 5 k7 &&
  -d - l - b == 8 k8,
 {k1, k2, k3, k4, k5, k6, k7, k8, u, d, l, r, f, b},
 Integers]
```

Solving mod 40 over the integers gives us
x1 = c1
x2 = 2 c2
u = c7
d = -12 c1 - 5 c2 - 20 c3 + c7
l = c8
r = -12 c1 - 35 c2 - 20 c3 + c8
f = 32 c1 - c7 - c8
b = 4 c1 + 5 c2 + 20 c3 - c7 - c8

This can be further simplified by setting c3 = c7 = c8 = 0 and changing some values mod 40. Then

c1 = x1
c2 = x2 / 2

u = 0
d = -12 c1 - 5 c2
l = 0
r = -12 c1 + 5 c2
f = -8 c1
b = 4 c1 + 5 c2

The equation for x2 implies that the big gear can only be 0, 2, 4, 6 teeth off. Once I got a situation where I accidentally split two layers half way and somehow the big gear ended up 1 or 3 off. This is actually an illegal state and needs to be fixed: see RedKB's video. Ever since I've been more careful and this hasn't happened.

Example solve: after basic steps, UBR gear is 4 teeth CW. Then x1 = 0 and x2 = 4, so c1 = 0 and c2 = 2.
This gives us our moves necessary: d = -10, r = 10, b = 10 (D10' R10 B10). This means turn a small gear on D layer 2 full turns CCW, small gear on R layer 2 full turns CW, and small gear on B layer 2 full turns CW. If the number is a multiple of 8, it's probably easier to turn the big gear CCW than little gear CW.

The hardest solves are when the values are not a multiple of 5 or 8, like 19 or 29. I haven't come up with a good way of these turns other than just counting the teeth by fives. Since these solves are hard to do without writing down, I'd like to know if anyone has further simplifications.


----------



## qwr (Jul 15, 2020)

Ok I have an actually intuitive method. It's based on the idea of only doing full big gear or little gear turns. For example to turn UFR, R8 (turning little gear CW by 8 teeth, big gear CCW one full turn) will affect UFR and DBR gears by +8, leaving big UBR and and DFR gears unchanged. Then D8' returns DBR to original and sets DFR to -8. Then F8 returns DFR to original and sets UFR to +16 = +1. Actually if we used 2 big gear spins instead, UFR would be +2, and if we did inverse spins, we could easily get UFR to -1 or -2 (all mod 5).

Similar idea applies for big gears. Doing R5 D5' B5, will affect UBR by -10 = -2, so we can get any value of -2, 2, 4 (mod 8)


----------

