# Turn the dials until each of the 12 columns add up to 42

I received the wooden puzzle below for Christmas. After playing with it for a while I decided I needed to actually write something down if I was going to solve it. Eventually I just wrote an algorithm that went through the 20736 possible positions of the 4 dials and found the only answer. The problem is I feel like I cheated/missed something.

Could I have done better than brute force?

Here is the puzzle.

On the rear is the text:

Solving the Greek Computer. Turn the dials until each of the 12 columns add up to 42

And here are the tables I created of the puzzle so you have all the numbers (0 always represents a hole in that dial):

3   0   6   0   10  0   7   0   15  0   8   0
0   0   0   0   0   0   0   0   0   0   0   0    Dial 1 (top)
0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0

6   17  7   3   0   6   0   11  11  6   11  0
12  0   4   0   7   15  0   0   14  0   9   0    Dial 2
0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0

9   13  9   7   13  21  17  4   5   0   7   8
21  6   15  4   9   18  11  26  14  1   12  0    Dial 3
5   0   10  0   8   0   22  0   16  0   9   0
0   0   0   0   0   0   0   0   0   0   0   0

11  0   8   0   16  2   7   0   9   0   7   14
14  12  3   8   9   0   9   20  12  3   6   0    Dial 4
9   0   17  19  3   12  3   26  6   0   2   13
6   0   10  0   10  0   1   0   9   0   12  0

11  11  14  11  14  11  14  14  11  14  11  14
4   5   6   7   8   9   10  11  12  13  14  15   Base (bottom)
4   4   6   6   3   3   14  14  21  21  7   9
8   3   4   12  2   5   10  7   16  8   9   8


And the solution:

(note I marked the answer so I can get to it easily)

• Welcome to Puzzling! Can you clarify if every zero in the text version is a "hole" in the physical puzzle (so you can see through to the layer below), or are there actual zeros anywhere?
– fljx
Commented Jan 24, 2022 at 12:04
• Yes, all the zeros are holes that reveal a number below. All the numbers start from 1. Commented Jan 24, 2022 at 12:34
• You are relying on the picture - do you have 5 wheels that are freely to rotate?
– Moti
Commented Jan 25, 2022 at 5:24
• I would consider the base static (the last table) then the other 4 dials freely rotate above it. That gives me 12^4 = 20736 positions of the 4 dials above the base. Commented Jan 25, 2022 at 10:12
• I have one of these and FWIW in the last two rows, next-to-last column, the 7 and 9 are transposed on mine but there is still only one solution that I found (they are unused). I haven't made any progress on a logical solution. Commented Feb 3, 2022 at 15:33

Yes, it can be solved smartly 'by hand'

-(1) 3 dials have repeating open-closed outer rings
-(2) It is very likely that the puzzle is constructed with the numbers of each ring of each dial having a function. Most important: the bottom dial most likely shows a number in dial one.
I started using (1) to look at (odd/even column) totals (and it turns out 2 is not needed)

Supporting picture

Case 1: (the teeth of) dial 1 and 3 align:
Looking at the teeth column total:
49 + ? + 70 + 48/49/43 = 6*42
? = 252 - 167/168/162
? = 85/86/90

? = 46 + 1 hole (a) or 15+ 5 holes (b)
(a) the hole must show 39/40/44 -> those numbers are not available.
(b) the 5 holes are all covered by dial 3 (1 dial 3 number covered by 15)
dial 3 numbers inward of its teeth : 21 15 9 11 14 12 => total 82
covered is 82 + 15 - 90/86/85 = 7/11/12
(b1) 11 covered
{21+5.., 15+10.., 9+8.., 15+22.., 14+16.., 12+9..} must combine with {5 10 8 22 16 9} and {6 10 10 1 9 12}
15+22 only needs 5 more -> no solution
(b2 )12 covered
{21+5.., 15+10.., 9+8.., 11+22.., 14+16.., 15+9..} must combine with {5 10 8 22 16 9} and {8 4 2 10 16 9}
11+22 needs 9 more -> 5 with 4 is the only match -> the other 5 also match.
When checking the other half of the puzzle we find that we have indeed a solution!

If (the teeth of) dial 1 and 3 do not align

Case 2: if dial 1 and 4 align {3, 6, 10, 7, 15, 8} must align with {..9+6,..17+10,..3+10,..3+1,..6+9,..2+12}
3+1+15 requires 23: not available
3+1+10 requires 28: already higher than available
-> no solution

Case 3: if dial 1 aligns with neither 3 nor 4
the following numbers matter for the teeth of dial 1:
ring 1: 3 6 10 7 15 8
dial 2, case X
ring 2: ?????15
dial 2, case Y
ring 2: 12,4,7,?,14,9
dial 3
ring 2: 6 4 18 26 1 ?
dial 4
ring 2: 12 8 ? 20 3 ?
ring 3: ? 19 12 26 ? 13
bottom, case A
ring 3: 4 6 3 14 21 7
ring 4: 8 4 2 10 16 9
bottom, case B
ring 3: 4 6 3 14 21 9
ring 4: 3 12 5 7 8 8

26 combines with at least 3 from ring 1 and at least 2 from ring 4, so must combine with at most 11 from ring 2 i.e. 26 must combine with 4,7 or 9 of case Y
26+9 leaves 7 -> only 3,9,26,4 possible (opposing side: 7,7,6,4 not42)
26+7 leaves 9 -> 7,7,26,2 and 6,7,26,3 possible (opposing side: 3,9,14,7 and 15,9,7,9 bothnot42)
26+4 leaves 12-> 3,4,26,9 and 7,4,26,5 and 8,4,26,4 and 10,4,26,2 (opposing side: 7,14,3,2 and 3,14,9,8 and 10,14,21,16 and 8,14,7,9 allnot42)

So the earlier found solution is unique.

• I am trying to follow your logic with the puzzle in hand but I am getting lost when you start talking about the holes ? = 46 + 1 hole (a) or 15+ 5 holes (b) (a) the hole must show 39/40/44 -> those numbers are not available. Which holes in which dial(s). Is this in reference to your point 2 in the initial section? I think you are right, I really like the sum the teeth approach, the fact dials 1,3,4 align or not, and I would like to award you the accept, but as I can't follow it properly I feel it needs a bit more clarification first. Commented Jan 6, 2023 at 11:36
• @Martin Do you think the added picture helps enough? Commented Jan 6, 2023 at 14:06

You can solve the problem via integer linear programming as follows. Let $$D=\{0,\dots,4\}$$ be the set of dials (where the top dial is $$0$$ and the bottom dial is $$4$$), let $$I=\{0,\dots,3\}$$ be the set of rows, and let $$J=\{0,\dots,11\}$$ be the set of columns. Let $$a_{dij}$$ be the number appearing on dial $$d$$ in row $$i$$ and column $$j$$, as given in the tables. Let $$R=J$$ be the set of rotations.

There are three sets of decision variables:

• For $$i\in I$$ and $$j \in J$$, let $$x_{ij}\in\{1,\dots,26\}$$ be the exposed value in row $$i$$ and $$j$$.
• For $$d\in D$$ and $$r\in R$$, let $$y_{dr}\in\{0,1\}$$ indicate whether dial $$d$$ is rotated $$r$$ times.
• For $$i\in I$$, $$j \in J$$, and $$d\in D$$, let $$z_{ijd}\in\{0,1\}$$ indicate whether the exposed value in row $$i$$ and $$j$$ arises from dial $$d$$.

The constraints are: \begin{align} \sum_{i\in I} x_{ij} &= 42 &&\text{for j\in J} \tag1\label1\\ \sum_{r\in R} y_{dr} &= 1 &&\text{for d\in D} \tag2\label2\\ \sum_{d\in D} z_{ijd} &= 1 &&\text{for i\in I, j\in J} \tag3\label3\\ -25(1-z_{ijd}) \le x_{ij} - \sum_{r \in R} a_{d,i,j+r \pmod{12}} y_{dr} &\le 25(1-z_{ijd}) &&\text{for i \in I, j \in J, d \in D} \tag4\label4\\ z_{ijd} &\le \sum_{\substack{r \in R\\a_{d',i,j+r \pmod {12}} = 0}} y_{d'r} && \text{for i \in I, j \in J, d \in D, d' \in D such that d' < d} \tag5\label5 \end{align} Constraint \eqref{1} enforces the column sums. Constraint \eqref{2} selects one rotation per dial. Constraint \eqref{3} selects one dial per exposed value. Constraint \eqref{4} enforces $$z_{ijd} = 1 \implies x_{ij} = \sum_{r \in R} a_{d,i,j+r \pmod{12}} y_{dr}.$$ Constraint \eqref{5} forces the chosen value to be exposed.

Without loss of generality, we can fix $$y_{00}=1$$. The resulting solution turns out to be unique, with $$x_{ij}$$ as follows:

 3 14  6  8 10 11  7 11 15  6  8  7
14  7 15 13 21 14 15  9  9 12 11  4
16 14  9 13  5  9 10 19  8 12 22 26
9  7 12  8  6  8 10  3 10 12  1  5


By request, here is the SAS code I used. The IMPLIES keyword automatically generates the corresponding big-M constraints.

proc optmodel;
num numDials = 5;
num numRows = 4;
num numCols = 12;
set DIALS = 0..numDials-1;
set ROWS = 0..numRows-1;
set COLS = 0..numCols-1;
set ROTATIONS = COLS;

num a {DIALS, ROWS, COLS} = [
3   0   6   0   10  0   7   0   15  0   8   0
0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0

6   17  7   3   0   6   0   11  11  6   11  0
12  0   4   0   7   15  0   0   14  0   9   0
0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0

9   13  9   7   13  21  17  4   5   0   7   8
21  6   15  4   9   18  11  26  14  1   12  0
5   0   10  0   8   0   22  0   16  0   9   0
0   0   0   0   0   0   0   0   0   0   0   0

11  0   8   0   16  2   7   0   9   0   7   14
14  12  3   8   9   0   9   20  12  3   6   0
9   0   17  19  3   12  3   26  6   0   2   13
6   0   10  0   10  0   1   0   9   0   12  0

11  11  14  11  14  11  14  14  11  14  11  14
4   5   6   7   8   9   10  11  12  13  14  15
4   4   6   6   3   3   14  14  21  21  7   9
8   3   4   12  2   5   10  7   16  8   9   8
];
for {d in DIALS} print {i in ROWS, j in COLS} a[d,i,j];

num aMin = min {d in DIALS, i in ROWS, j in COLS} max(a[d,i,j],1);
num aMax = max {d in DIALS, i in ROWS, j in COLS} a[d,i,j];
put aMin= aMax=;

var X {ROWS, COLS} >= aMin <= aMax;
var Y {DIALS, ROTATIONS} binary;
var Z {ROWS, COLS, DIALS} binary;

con SumTo42 {j in COLS}:
sum {i in ROWS} X[i,j] = 42;

con OneRotation {d in DIALS}:
sum {r in ROTATIONS} Y[d,r] = 1;

con OneDial {i in ROWS, j in COLS}:
sum {d in DIALS} Z[i,j,d] = 1;

con Indicator1 {i in ROWS, j in COLS, d in DIALS}:
Z[i,j,d] = 1 implies X[i,j] = sum {r in ROTATIONS} a[d,i,mod(j+r,numCols)] * Y[d,r];

con Indicator2 {i in ROWS, j in COLS, d in DIALS, d2 in DIALS: d2 < d}:
Z[i,j,d] <= sum {r in ROTATIONS: a[d2,i,mod(j+r,numCols)] = 0} Y[d2,r];

fix Y[0,0] = 1;

solve noobj;

print X;
quit;

• I like this answer, it reminds me of reading Wikipedia. It also leaves with the same feeling of, I wish I knew maths better. I can kind of skim read your answer and to my programmer brain it reads as a bunch of for loops over a bunch of sets with some restrictions i.e. the maths version of my code to brute force the answer. There are some things I don't understand at all, where does the -25, 25 come from in Constraint 4, but mostly it is how to make "Without loss of generality..." not just be "And magic...". How do you plug the original matrices into those formula to remove the brute force? Commented Jan 3, 2023 at 15:05
• The implicit loops are for declaring the constraints, but the actual solution process (branch-and-bound) is typically much more efficient than brute force. The "without loss of generality" corresponds to your assumption that the base is fixed. The $\pm 25$ coefficients arise from "big-M" constraints. In general, the implication $z=1 \implies f(x)=b$ can be enforced as $-M(1-z) \le f(x) - b \le M(1-z)$, where $M$ is a constant chosen to make the inequalities redundant when $z=0$. Here, $M=26-1$, the difference between the largest and smallest values in the dials. Commented Jan 3, 2023 at 17:00
• Did you plug the data into a tool you can give a link to? i.e. where you ran the branch and bound, to get the solution Commented Jan 4, 2023 at 12:43
• @Martin, I added the SAS code to my answer just now.. Commented Jan 4, 2023 at 17:34

I observed that all the outmost band numbers on rings 2 and 3 (counting 1 from the bottom) are always used. So they must be used in the final solution. I started with the largest number on outmost ring 2 - 12. So rings 2/3 contribution to the final solution is 12-10, 12-5, 12-9, 12-16, 12-22, or 12-8. 12-2 is also a potential. I picked 12 because it was easier mentally to find the difference from 30 (42-12) rather than add 4 numbers to test for 42. Then with each pair in turn fixed, I ran though the permutations of rings 4 and 5 looking for 42s. This was just looking for the difference from the sum of our pairs. Example for 12-10. 42-12-10=20. Just look for pairs on rings 4 and 5 that equal 20.

Realize that if a 42 from the final solution is found, each spoke defined by ring 2 will also be 42. 42s not of the final solution will be found when running through the permutations of rings 4 and 5. But if the 42 from the final solution is found, the 6 columns defined by ring 2 will all total 42.

Once the 6 42 columns defined above are found, check one of the other remaining 6 columns for 42. Rotate rings 2, 3, 4, 5 as a unit maintaining their 42s until the remaining 6 columns all total 42.

• It would make it much easier to understand your process if you used the dial numbers I defined in the original post. However I do like the approach as it cuts the problem in half before you even start then makes the search significantly easier to find the solution. It is similar to the solution I accepted in that it identifies that the key to a fast solution is in the teeth of the dials. Commented Jan 13, 2023 at 11:56

For the rest of the answer I'll be referencing the dials as posted in the question in R1C1 style. For example, in the initial configuration, Dial 1 R1C5 is 10. Shown below:

    c1  c2  c3  c4  c5...
r1  3   0   6   0   10  0   7   0   15  0   8   0
r2  0   0   0   0   0   0   0   0   0   0   0   0
r3  0   0   0   0   0   0   0   0   0   0   0   0
r4  0   0   0   0   0   0   0   0   0   0   0   0


Also, I'll give values for the dials as Dx=y meaning Dial x has been shifted right y spaces. For example, D1=2 would create the following state of Dial 1:

8   0   3   0   6   0   10  0   7   0   15  0
0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0


I found a break-in using the first two dials. Note that D1 only covers every second column, so either the even columns of rows 1 and 2 are showing on D2 or the odd columns are. Assuming the even columns show, this is what the first two rows of D2 are like:

?   17  ?   3   ?   6   ?   11  ?   6   ?   0
?   0   ?   0   ?   15  ?   0   ?   0   ?   0


Note that under the assumption, the sum of R1C6 and R2C6 is now set at 21. It isn't too difficult from here to enumerate all possible ways to create 21 in R3C6 and R4C6, since that only involves D3, D4 and the base. As such, it's easier to consider D2 as static and rotate the layers underneath. With D2=0, the solutions for C6 are:

1. D3=5, base=9, D4 even (to create a hole in R4C6)
2. D3=9, base=0, D4 even
3. D3=7, D4=7
4. D3=7, base=2, D4 even
5. D4=6, base is any of 5, 6 or 8, D3 even (to create a hole in R3C6)
6. D4=2, base=1, D3 even
7. D4=0, base=7, D3 even
8. base=10, D4=8, D3 even

However, none of these solutions can simultaneously satisfy the remaining columns. For example, consider R1C2 and R2C2, which are 17 and 0, and the first C6 solution listed above (D3=5, base=9, D4 even). This would produce R2C2=14, R3C2=16, R4C2=2, which is a sum of 49. There are three solutions that satisfy C2 and C6 but then those don't satisfy C4. Therefore, the initial assumption was incorrect, and it must be the odd columns of D2 that show in the final solution.

Using a similar strategy of enumerating all possibilities for one column and seeing if they satisfy the remaining ones, the only remaining possibility is D2=0, D4=7, base=9 and D3 and D1 both odd. This cuts down the search space to a mere 36 possibilities, which I think is a reasonable number to check by hand.

• "This would produce R2C2=14, R3C2=16, R4C2=2, which is a sum of 49." but that sums 32. I'm still trying to work through your process with my puzzle. Commented Jan 18, 2023 at 12:53
• Also add R1C2, which is 17. Commented Jan 18, 2023 at 19:45

I was wondering if there was a computational way to solve the puzzle, but I did it manually. I realized the numbers on the lowest rotating ring were the key. I first created a solution that solved those numbers at the same time. When that was solved, I rotated the bottom disk until I got two additional columns solved for 42. Then I checked the rest and now all columns totaled 42. I was looking to see if there was a second configuration, but from what I found there seems to be only one.

• Why does dial 4 give a better starting point (are the key) than any of the other dials, or the base? Commented Jan 3, 2023 at 15:11

I did this excel macro. I used a pure brute force method. I modified it a couple of times just to run it through the whole process to see íf it found any other answers. It did not.

Sub rotar()
Range("M17:X30").Select
Selection.Copy
Range("A2").Select
ActiveSheet.Paste
Range("M2").Select
ActiveSheet.Paste

Application.ScreenUpdating = False

'grande se queda fija
For i = 1 To 12 'segunda
For j = 1 To 12 'tercera
For k = 1 To 12 'cuarta
For l = 1 To 12 ' quinta
'numero = Range("Z29")
If Range("Z29") = 504 And Range("A29") = 42 And Range("C29") = 42 Then
Range("A24:L27").Select
Application.CutCopyMode = False
Selection.Copy
Range("A32").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
GoTo fin
End If
Range("B6:M9").Select
Selection.Copy
Range("A6").Select
ActiveSheet.Paste
Range("M6:M9").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft

Next
Range("M21:X24").Select
Selection.Copy
Range("M6").Select
ActiveSheet.Paste

Range("B10:M12").Select
Selection.Copy
Range("A10").Select
ActiveSheet.Paste
Range("M10:M12").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Next
Range("M25:X27").Select
Selection.Copy
Range("M10").Select
ActiveSheet.Paste

Range("B13:M14").Select
Selection.Copy
Range("A13").Select
ActiveSheet.Paste
Range("M13:M14").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft

Next
Range("M28:X29").Select
Selection.Copy
Range("M13").Select
ActiveSheet.Paste

Range("B15:M15").Select
Selection.Copy
Range("A15").Select
ActiveSheet.Paste
Range("M15").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft

Next

fin:

Application.ScreenUpdating = True

End Sub


I went around rotating all the discs to get a single row to 42, then seeing what options I had left, eventually I got the hole down to the 14 on the (14-7-14-7) row. After that, 6 rows were solved and I just needed to spin the top gear.