Skip to main content
Commonmark migration
Source Link

#A random configuration of gears is solvable 1/3 of the time*

A random configuration of gears is solvable 1/3 of the time*

#A random configuration of gears is solvable 1/3 of the time*

A random configuration of gears is solvable 1/3 of the time*

Incorporate the changes suggested by commenters.
Source Link
justhalf
  • 6k
  • 2
  • 32
  • 49

#It's almost always solvable*#A random configuration of gears is solvable 1/3 of the time*

For details on what kind of configuration is solvable, refer to the claim after the image below.

As OP noticed, locking one gearClaim: An initial configuration is solvable if and only if the sum of states of gears A+F+I is the same as the sum of states of gears C+E+H (modulo 3) (and its connected gearsproof comes later at the bottom) and then rotate all

This means, given the states of five gears clockwisefrom ACEFHI, there is only one possible state of the same as rotating those locked gears counter-clockwise followed by rotating all gears clockwiseother gear that leads to a solvable state.

Now to the solution.

As OP noticed, and this is one important observation, locking one gear (and its connected gears) and then rotate all gears clockwise is the same as rotating those locked gears counter-clockwise followed by rotating all gears clockwise. Let's denote by capital letters the number of clockwise rotations required by the respective gear so that we reach a solved state.

*HoweverHowever, notice that previously we ignore one equation. Plugging in the values we obtained into the equation, we have:


*However, in the Puzzlopia gear puzzle, as the other answer noted, I think it should always be solvable since the initial configuration is not random, but, similar to how one generate 15-puzzle (the sliding puzzle), the puzzle can be created by starting from a solved state and then performing a sequence of random rotations.

#It's almost always solvable*

As OP noticed, locking one gear (and its connected gears) and then rotate all gears clockwise is the same as rotating those locked gears counter-clockwise followed by rotating all gears clockwise. Let's denote by capital letters the number of clockwise rotations required by the respective gear so that we reach a solved state.

*However, notice that previously we ignore one equation. Plugging in the values we obtained into the equation, we have:

#A random configuration of gears is solvable 1/3 of the time*

For details on what kind of configuration is solvable, refer to the claim after the image below.

Claim: An initial configuration is solvable if and only if the sum of states of gears A+F+I is the same as the sum of states of gears C+E+H (modulo 3) (proof comes later at the bottom)

This means, given the states of five gears from ACEFHI, there is only one possible state of the other gear that leads to a solvable state.

Now to the solution.

As OP noticed, and this is one important observation, locking one gear (and its connected gears) and then rotate all gears clockwise is the same as rotating those locked gears counter-clockwise followed by rotating all gears clockwise. Let's denote by capital letters the number of clockwise rotations required by the respective gear so that we reach a solved state.

However, notice that previously we ignore one equation. Plugging in the values we obtained into the equation, we have:


*However, in the Puzzlopia gear puzzle, as the other answer noted, I think it should always be solvable since the initial configuration is not random, but, similar to how one generate 15-puzzle (the sliding puzzle), the puzzle can be created by starting from a solved state and then performing a sequence of random rotations.

Add code
Source Link
justhalf
  • 6k
  • 2
  • 32
  • 49

I can prove that the upperbound of the number of rotations is 8. As previously noted, rotating A, D, F, I rotates all gears exactly once. I'll prove that A+D+F+I <= 2. By pigeonhole principle, since there are 4 variables and 3 values (0, 1, 2), there are one value that is assumed by two of the variables. If it is 0, then two of the gears do not need rotation. So maximum 7 gears need rotations + maximum 1 from global rotation, so maximum 8 rotations. If it is not 0, then we can make them 0 by changing the global rotation direction. So maximum 8 rotations. 

I haven't founddon't know (so far) how to prove that a configuration that requires at least 8 rotations, so it might be that all solvable configuration can be solved in 7 rotations maximum. One example of initial state that my solution says it requires 8 rotations is this:


2 2 2 1 2 0 2 0 2

You might notice that the state e is missing from the solution. This is because knowing a, c, f, h, and i gives a unique e for which there is a solution, and so the state of e is immaterial to our solution that already uses the other 8 states.


Code to calculate

Below I give the code in Python to calculate the solution as above, including the heuristics to minimize the number of rotations.

"""
21 Nov 2016
To solve the GEAR puzzle at puzzlopia (if not logged in)
"""

# Import statements
from builtins import input
from itertools import product

def count_zero(arr):
    return sum(1 if val==0 else 0 for val in arr)

def add_one(arr):
    return [(val+1)%3 for val in arr]

def compute(*vals):
    a,b,c,d,e,f,g,h,i = vals
    A = ( a-b+c      +g-h-i+9)%3
    B = ( a+b-c      -g+h+i+9)%3
    C = (-a+b+c-d          +9)%3
    D = (       d    +g-h-i+9)%3
    E = (       d    -g+h+i+9)%3
    F = ( a-b-c-d  -f-g-h+i+9)%3
    G = (                -i+9)%3
    H = (      -d    +g+h-i+9)%3
    I = (0                 +9)%3
    arr = [A,D,F,I]
    if count_zero(arr) < 2:
        arr = add_one(arr)
    if count_zero(arr) < 2:
        arr = add_one(arr)
    A,D,F,I = arr
    return (A,B,C,D,E,F,G,H,I)

def main():
    a, b, c, d, e, f, g, h, i = map(int, input('Enter values:').split()) #(0, 1, 0, 1, 0, 1, 0, 1, 0)
    A,B,C,D,E,F,G,H,I = compute(a,b,c,d,e,f,g,h,i)
    print('A={}\nB={}\nC={}\nD={}\nE={}\nF={}\nG={}\nH={}\nI={}'.format(A,B,C,D,E,F,G,H,I))

if __name__ == '__main__':
    main()

I can prove that the upperbound of the number of rotations is 8. As previously noted, rotating A, D, F, I rotates all gears exactly once. I'll prove that A+D+F+I <= 2. By pigeonhole principle, since there are 4 variables and 3 values (0, 1, 2), there are one value that is assumed by two of the variables. If it is 0, then two of the gears do not need rotation. So maximum 7 gears need rotations + maximum 1 from global rotation, so maximum 8 rotations. If it is not 0, then we can make them 0 by changing the global rotation direction. So maximum 8 rotations. I haven't found a configuration that requires at least 8 rotations, so it might be that all solvable configuration can be solved in 7 rotations maximum.

You might notice that the state e is missing from the solution. This is because knowing a, c, f, h, and i gives a unique e for which there is a solution, and so the state of e is immaterial to our solution that already uses the other 8 states.

I can prove that the upperbound of the number of rotations is 8. As previously noted, rotating A, D, F, I rotates all gears exactly once. I'll prove that A+D+F+I <= 2. By pigeonhole principle, since there are 4 variables and 3 values (0, 1, 2), there are one value that is assumed by two of the variables. If it is 0, then two of the gears do not need rotation. So maximum 7 gears need rotations + maximum 1 from global rotation, so maximum 8 rotations. If it is not 0, then we can make them 0 by changing the global rotation direction. So maximum 8 rotations. 

I don't know (so far) how to prove that a configuration that requires at least 8 rotations, so it might be that all solvable configuration can be solved in 7 rotations maximum. One example of initial state that my solution says it requires 8 rotations is this:


2 2 2 1 2 0 2 0 2

You might notice that the state e is missing from the solution. This is because knowing a, c, f, h, and i gives a unique e for which there is a solution, and so the state of e is immaterial to our solution that already uses the other 8 states.


Code to calculate

Below I give the code in Python to calculate the solution as above, including the heuristics to minimize the number of rotations.

"""
21 Nov 2016
To solve the GEAR puzzle at puzzlopia (if not logged in)
"""

# Import statements
from builtins import input
from itertools import product

def count_zero(arr):
    return sum(1 if val==0 else 0 for val in arr)

def add_one(arr):
    return [(val+1)%3 for val in arr]

def compute(*vals):
    a,b,c,d,e,f,g,h,i = vals
    A = ( a-b+c      +g-h-i+9)%3
    B = ( a+b-c      -g+h+i+9)%3
    C = (-a+b+c-d          +9)%3
    D = (       d    +g-h-i+9)%3
    E = (       d    -g+h+i+9)%3
    F = ( a-b-c-d  -f-g-h+i+9)%3
    G = (                -i+9)%3
    H = (      -d    +g+h-i+9)%3
    I = (0                 +9)%3
    arr = [A,D,F,I]
    if count_zero(arr) < 2:
        arr = add_one(arr)
    if count_zero(arr) < 2:
        arr = add_one(arr)
    A,D,F,I = arr
    return (A,B,C,D,E,F,G,H,I)

def main():
    a, b, c, d, e, f, g, h, i = map(int, input('Enter values:').split()) #(0, 1, 0, 1, 0, 1, 0, 1, 0)
    A,B,C,D,E,F,G,H,I = compute(a,b,c,d,e,f,g,h,i)
    print('A={}\nB={}\nC={}\nD={}\nE={}\nF={}\nG={}\nH={}\nI={}'.format(A,B,C,D,E,F,G,H,I))

if __name__ == '__main__':
    main()
Add proof for maximal rotations required for any puzzle
Source Link
justhalf
  • 6k
  • 2
  • 32
  • 49
Loading
Source Link
justhalf
  • 6k
  • 2
  • 32
  • 49
Loading