Rubik's Clock is a round(ish) puzzle with two flat sides. On each side, front and back, there are 9 clock faces, arranged on a 3x3 grid. In addition, there are 4 pegs (switches) in between the clock faces, and they can be set to protrude either from the front or the back. Lastly, there are 4 dials on the edge of the puzzle. You can rotate them to manipulate the 4 clocks in the corners, on the front and the back simultaneously. Here's a schematic.
The switches each have 4 clocks around them, and they act as a lock to those 4 clocks. If a switch is pressed in, any movement of any of the surrounding clocks is synchronised with the three others. If the switch is not pressed in, they move independently. However, in that case, it can be seen as pressed in from the other side. Therefore, the 4 clocks around the switch on the other side of the puzzle are synchronised. The switches thus always lock 4 clocks together, either on the front or the back.
For consistency in clockwiseness and switch settings, we define one side as the front and the other as the back. As seen from the front, the switches are set to 1 if they are pressed in, and 0 if they are not pressed in.
The four corner clocks are inversely synchronised between the front and the back. If you were to turn a dial clockwise, the clock on the backside in the same position would turn counter-clockwise. Therefore, there is a total of 14 independent clocks: 4 corners, 5 independent on the front and 5 independent on the back.
Consider an example where all clocks are set to 0 (or 12), switch 0 is set to 1 and the other switches are set to 0. If we turn dial 0 to position 2, the following happens:
- Front clocks 1, 3 and 4 are synchronised to clock 0 and all move to position 2
- Back clock 0 is inversly synchronised to clock 0 and moves to position 10 (= -2 mod 12)
Now consider the same example, but instead both switches 0 and 3 are set to 1, whereas switches 1 and 2 are set to 0. If we turn dial 0 to position 2 again, the following happens:
- Front clocks 1, 3 and 4 are synchronised to clock 0 and all move to position 2
- Front clocks 5, 7 and 8 are synchronised to clock 4 and all move to position 2
- Back clock 0 is inversely synchronised to clock 0 and moves to position 10 (= -2 mod 12)
- Back clock 8 is inversely synchronised to clock 8 and moves to position 10 (= -2 mod 12)
The aim of the puzzle, given a scrambled set of clocks, is to set all clocks to 0. You do this by flipping switches and turning dials appropriately. This is also the task of the challenge.
The challenge
Given a valid setting for both the front and back clocks, output a sequence of switch settings and dial turns which set all clocks to 0.
Rules
- Input and output are flexible to the extent permitted by the default rules, provided that they unambiguously describe the clock and the required sequence.
- You can redefine the indexing.
- If convenient, you can take only the 14 unique clock faces as input.
- Clocks on the front must always respond directly (positively) to dial turns.
- Clocks on the back must always respond inversely to dial turns.
- Consider all switches set to 0 at the start of the solve.
- The final switch settings can be nonzero, as long as all clocks are solved.
- Your program must finish in a reasonable amount of time: no brute-forcing.
Examples
Example input: [9, 9, 0, 9, 9, 0, 9, 9, 0], [3, 0, 0, 0, 0, 0, 3, 0, 0]
Example output: [0, 2, (2, 3)]
| | +---- Dial turn
+--+---------- Switch flips
Step-by-step:
Current state
Switches: 0 0 0 0
Front: Back:
9 9 0 | 3 0 0
9 9 0 | 0 0 0
9 9 0 | 3 0 0
Flipping switch 0
Flipping switch 2
Turning dial 2; 3 times
Current state
Switches: 1 0 1 0
Front: Back:
0 0 0 | 0 0 0
0 0 0 | 0 0 0
0 0 0 | 0 0 0
Example input: [11, 0, 11, 8, 8, 8, 8, 8, 8], [1, 1, 1, 1, 1, 1, 4, 0, 4]
Example output: [2, 3, (2, 4), (1, 1)]
Step-by-step:
Current state
Switches: 0 0 0 0
Front: Back:
11 0 11 | 1 1 1
8 8 8 | 1 1 1
8 8 8 | 4 0 4
Flipping switch 2
Flipping switch 3
Turning dial 2; 4 times
Current state
Switches: 0 0 1 1
Front: Back:
11 0 11 | 1 1 1
0 0 0 | 1 1 1
0 0 0 | 0 0 0
Turning dial 1; 1 times
Current state
Switches: 0 0 1 1
Front: Back:
0 0 0 | 0 0 0
0 0 0 | 0 0 0
0 0 0 | 0 0 0
Example input: [3, 11, 0, 11, 11, 5, 2, 11, 1], [9, 8, 0, 8, 8, 4, 10, 8, 11]
Example output: [1, 3, (2, 9), (0, 7), 0, 1, 2, 3, (0, 6), 2, 3, (3, 7), 0, 1, 2, 3, (0, 4)]
Step-by-step:
Current state
Switches: 0 0 0 0
Front: Back:
3 11 0 | 9 8 0
11 11 5 | 8 8 4
2 11 1 | 10 8 11
Flipping switch 1
Flipping switch 3
Turning dial 2; 9 times
Current state
Switches: 0 1 0 1
Front: Back:
0 11 0 | 0 11 0
11 11 5 | 11 11 4
11 11 1 | 1 11 11
Turning dial 0; 7 times
Current state
Switches: 0 1 0 1
Front: Back:
7 11 0 | 5 4 0
11 11 5 | 4 4 4
6 11 1 | 6 4 11
Flipping switch 0
Flipping switch 1
Flipping switch 2
Flipping switch 3
Turning dial 0; 6 times
Current state
Switches: 1 0 1 0
Front: Back:
1 5 0 | 11 4 0
5 5 5 | 4 4 4
0 5 1 | 0 4 11
Flipping switch 2
Flipping switch 3
Turning dial 3; 7 times
Current state
Switches: 1 0 0 1
Front: Back:
8 0 0 | 4 4 0
0 0 0 | 4 4 4
0 0 8 | 0 4 4
Flipping switch 0
Flipping switch 1
Flipping switch 2
Flipping switch 3
Turning dial 0; 4 times
Current state
Switches: 0 1 1 0
Front: Back:
0 0 0 | 0 0 0
0 0 0 | 0 0 0
0 0 0 | 0 0 0