I wrote an exhaustive search script with the following Python code:
def solve(data, n=6):
# Who's turn? A=0,B=1,C=2
i = (n - 1) % len(data)
return {
x
for x in {
# the new hat configuration, subbing in
# this round's candidates into the existing
# hat configuration.
(*data[:i], x, *data[i + 1 :])
for x in {
a + x * b
for aa, a in enumerate(data)
if aa != i
for bb, b in enumerate(data)
if bb != i
and bb != aa
for x in (-1, 1)
}
# must be valid hat number
if x > 0
}
# recursion termination condition
if n == 1
or
# All previous rounds must not have produced a single candidate
all(len(solve(x, n - j)) == 2 for j in range(1, n))
}
v = 144
for i in range(10000):
for data in ((i, v - i, v), (i, v + i, v), (i, i - v, v)):
s = solve(data)
if all(x >= 1 for x in data) and len(s) == 1 and next(iter(s))[-1] == v:
print(data)
It returns the following answers:
32 112
36 108
54 90
64 80
108 36
The 36 108
solution matches that of the answers in the Question sources. But indeed the tree-search code above was able to find additional solutions, not mentioned in the sources. I was able to manually check 54 90
and 32 112
solution to confirm their validity.
How it works
The spirit
Every round, the current guesser needs to decide between two potential candidate-answers for themselves: a + b
or |a - b|
. If only one of the candidates is valid (i.e, positive integer), then the player can answer immediately with the only remaining candidate.
Otherwise, the current guesser must recall all prior rounds, and simulate the conclusions drawn by the previous players on their turns (including themselves from 3 rounds ago!!!). This is akin to a tree search, where a leaf node is pruned if a prior round would have deemed that candidate impossible. In turn, the player would then deduce that that entire half of the search tree is invalid, and must conclude that the other candidate is the valid one. If no leaf-pruning is possible across all rounds, then the player cannot determine their number and must pass.
The code
The code assumes we are on round 6 for person C.
Exhaustive search of candidate (A,B,C) pairs are passed to a validator solve
function, which returns all potential valid hats assuming n
rounds have elapsed, and all previous rounds have produced "I don't know" answers.
Then we simply select candidates which returned only a single candidate.