This is a classic puzzle often called "The Hardest Logic Puzzle" or a variant of the "100 prisoners and a light bulb" style puzzle, but here with an 8x8 board and flipping stones. The key insight is to use error-correcting codes or parity-based encoding to communicate the secret number by flipping exactly one stone.
Restating the Problem in Brief
- There is an 8x8 board (64 squares), each with a black or white stone.
- Prisoner A is told a secret number ( S \in {0, \ldots, 63} ).
- Prisoner A can flip exactly one stone on the board.
- Prisoner B sees the final board and must guess ( S ).
- Prisoners can agree on a strategy beforehand.
- Prisoner B does not know the initial board state or which stone was flipped.
Goal
Devise a strategy so that Prisoner B can always deduce ( S ) from the final board configuration.
The Key Idea: Use the Board as a 64-bit Codeword and Encode the Secret Number as a Parity Check
We can think of the board as a 64-bit binary vector, where each bit corresponds to a stone's color (e.g., 0 = white, 1 = black).
- Initial board state: ( B = (b_0, b_1, \ldots, b_{63}) )
- After flipping one stone at position ( f ), the new board state is ( B' ), which differs from ( B ) in exactly one bit.
Step 1: Assign indices to the stones
Number the stones from 0 to 63 in some agreed order (e.g., row-major order).
Step 2: Use the secret number ( S ) as a target parity
The prisoners agree on a parity function ( P ) that maps a board state to a 6-bit number (since ( 2^6 = 64 )).
For example, define ( P(B) ) as the XOR of the indices of all stones that are black (or 1):
[
P(B) = \bigoplus_{\substack{i=0 \ b_i=1}}^{63} i
]
Here, (\oplus) is bitwise XOR.
Step 3: Prisoner A's strategy
- Prisoner A is told the secret number ( S ).
- Prisoner A observes the initial board ( B ).
- Prisoner A computes ( p = P(B) ).
- Prisoner A wants to flip exactly one stone ( f ) so that the new board ( B' ) satisfies:
[
P(B') = S
]
Since flipping stone ( f ) toggles bit ( b_f ), the parity changes as:
[
P(B') = P(B) \oplus f
]
because flipping stone ( f ) adds or removes ( f ) from the XOR sum.
Therefore, to get ( P(B') = S ), Prisoner A must choose:
[
f = p \oplus S
]