Impossible Chessboard Escape Puzzle

Solution implementation by Cory Leigh Rahman

GitHub Repo: CoryLR/impossible-chessboard-escape-puzzle

Puzzle Prompt

Prisoner 1 walks in to a room, sees a chessboard where each square has a coin on top, flipped either to heads or tails. The warden places the key under one of the squares, which prisoner 1 sees. Before he leaves, he must turn over one and only one coin. Prisoner 2 then walks in and is supposed to be able to figure out which squares the key is in just by looking at the arrangement of coins. The Prisoners can coordinate a plan ahead of time. What's the plan?

Here's how the scenario will go:

  1. The warden will set up the board while the prisoners come up with a plan
  2. Prisoner 1 will witness which chessboard square the warden places the key under, flip exactly one coin to try and convey this information, then leave
  3. Prisoner 2 will enter and have one chance to pick which square the key is under

Tools Used

SPOILER ALERT: If you want to solve this puzzle yourself, turn back now!

Set Up the Board

We need to make a representation of a chessboard with a randomly flipped coin in each square

The Prisoners Hatch a Plan

First the prisoners decide to give each square a unique ID:

Because there are 64 squares each with their own unique ID (0 through 63), we need a minimum of 6 bits of information to represent any one square. For example:

Let's look at all the chessboard's square IDs in binary:

Now the challenge becomes how to precisely communicate 6 bits of information by flipping just one coin on the board.

The board can be split up in 6 groups and arranged in such a way so that one coin flip can reside in all, some, or none of the the groups. Now let's say we count the number of heads-up coins in each section. An even number of heads-up coins will mean 1, while an odd number of heads-up coins will mean 0. If we associate each of the 6 groups with one of the digits of a 6-bit binary string, then we can then construct a binary string like "100101" by counting the number of heads-up coins in each section.

Sections

Image Source: https://datagenetics.com/blog/december12014/index.html

This system enables Prisoner 1 to have total control over the board's inherent randomly encoded binary string. Prisoner 1 can change it to any number 0 to 63, allowing Prisoner 2 to decode this message and discover the location of the square containing the key.

For example, if you flip Square ID 0 then the chess board's initial, random encoded number will not change at all. If you flip the coin in Square ID 1 then only the first digit of the binary will change. If you flip the coin in Square ID 5, then exactly the first and third digits of the binary will change, and none others. This works with all combinations such that there is exactly one square on the board for every possible adjustment needed to correctly convey the ID of the square containing the warden's key.

The prisoners agree on the following section locations on the chessboard:

The prisoners then agree on the system to decode the chessboard into a 6-bit binary string:

Prisoner 1 is Shown Which Square Holds the Key

Now that we have our target key location, Prisoner 1 needs to determine:

  1. The initial, random binary string read from the 6 agreed-upon sections
  2. The target binary to change it to: the ID of the square containing the warden's key

Next we need to figure out which coin on the board will, when flipped, turn the board's initial binary value into the target binary value. This will allow Prisoner # 2 to read the read the location of the key from the board.

Prisoner 1 has determined that if they flip the coin in square above, then when Prisoner 2 decodes the binary value of the board, he will read the number of the square containing the key.

Next, Prisoner 1 will go ahead and flip the coin.

Prisoner 1 Leaves, Prisoner 2 Enters

Prisoner 2 walks in to see the following chessboard

Prisoner 2 decodes the binary value from the chessboard. Using the agreed-upon sections, they count the number of coins which are heads-up in each section. Depending on if each number was even or odd, they write either 1 or 0 as the next digit in the 6-digit binary number.

Next, Prisoner 2 finds which square the binary number represents:

Here's a recap using all the calculated values:

Testing the Solution