r/mathpuzzles • • Jun 28 '15

The Devil's Chessboard

This is a fun one I heard from my colleague:

You're locked in a room with the devil, and your friend is waiting outside. The only thing in the room besides you and the Devil is an empty chessboard, 63 identical coins, and a magic coin, which looks identical to the other 63 and cannot be distinguised by the human eye.

He takes each of the 64 coins and places each one, randomly heads or tails, on a square of the chessboard. He tells you (truthfully) which one is the magic coin.

You must turn over exactly one coin from heads to tails or vice versa and leave the room, after which your friend comes in. She must determine which coin is the magic coin. If she does, you both go free. Otherwise, you both spend eternity at the company barbeque.

You may discuss any strategy beforehand.

EDIT: If you want a hint, try a simpler scenario: a 2x2 chessboard with only 4 coins. Can you find a way to point to an arbitrary square? I will post the solution soon, just need to write it up.

EDIT 2: Solution below!

Are you sure you want to read the solution?

Last chance to turn back! Do it now!

Trust me, if you get it on your own, it's a great feeling.

Okay, fine:

Assume first (we'll come back to this), that there is an even number of heads, and an even number of tails. Additionally, we will count Tails as 0, and Heads as 1, just for simplicity. So we have an 8x8 matrix of 0s and 1s, which are entirely random. Here's what we're going to do:

We point to specific areas by marking particular rows / columns as odd. So, if we have a 2x2 matrix, and we want to point to a certain square, we make the row it's in and the column it's in odd, and the other ones even. If we take under assumption that the total sum of the matrix is even, then either the sum of each columns is even, or both have an odd sum. Exactly the same with the rows: either both are even, or both are odd.

So, if we want to point to a square, make its row odd if it's even, or make the other row even if your square is already in an odd row. Try it out now, it works! If you have, for example:

10

01

and we want to point to the upper right square, we make the left column and lower row both even by flipping the lower left coin. This is always possible, just choose the column and row which you want to flip.

Now, we just extend to an 8x8.

So to point to a single square in an 8x8, you can't guarantee that it's in the only odd row and odd column. What we do instead is narrow it down. We point first to either the right half or the left half of the board by making either the left 4 columns' or the right 4 columns' odd. This means you either have to turn over a coin on the left or the right, but you've already cut down your space. Next, we point to either the top half or bottom half by making the sum of either the top 4 rows or bottom 4 rows odd, and the other even. You've narrowed down the coin you have to flip to one of 16! This is actually identical to the 2x2 case.

Now, it gets a bit more tricky, but the same form of the problem: once you know which quadrant (4x4 square) the magic coin is in, we need to narrow down further. We need to narrow down to either the top two rows or bottom two rows. It gets a little tricky here. Because the coin we're flipping may be in a different quadrant, how do we make the top or bottom two rows even or odd? E.g., the magic coin is in the top right quadrant, and we know we need to flip a coin in the bottom left, how do we make sure we can still inform about the location? That's coming up, just want to make sure this part gets posted.

EDIT 3: Rest of the solution! I'm going graphical.

Let's say we want to choose this square: http://i.imgur.com/mINNsye.png. We make the right 4 columns odd, the top 4 rows odd, then the total sum of every pair of columns odd: the sum of 1, 2, 5, and 6 odd, and rows 3, 4, 7, and 8 odd. The red represents an odd sum, and the white an even sum. http://imgur.com/2hAunD9,z7yvqef,ST9iCsE,WqIJl4c We know this must always work: if the sum of columns 1, 2, 5, and 6 starts off as even, then the sum of 3, 4, 7, and 8 must also be even! Remember, we assumed a total even sum.

Lastly, to narrow down to the individual column and row, look at second column. We make columns 1, 3, 5 and 7 odd, and rows 1, 3, 5 and 7 odd! Notice the x is always in the red (sum is odd), and not in the white (even) Convince yourself this is always possible. http://imgur.com/o3xA0jv,9kYgfle

EDIT 4: Wrap-up / method.

Take the square where the magic coin is, e.g., row 3, column 5. Start with the columns. Count up the sum of 1-4 and 5-8. They're either both odd or both even. If they're both even, you'll be flipping a coin somewhere in columns 5-8. If they're both odd, columns 1-4. Next, take every pair of columns and add them up: the sum of (1, 2, 5, and 6), and the sum of (3, 4, 7, and 8). If they're both odd, you'll flip a coin in rows 3, 4, 7, or 8 to make that sum even, otherwise 1, 2, 5 or 6. Lastly, take the sum of columns (1, 3, 5, and 7), and (2, 4, 6, and 8). Do the same thing: you'll be flipping a coin in either an odd or even column. Now, you've narrowed down exactly which column you need to flip a coin in! There's exactly one column which satisfies the constraints you just placed. Do the exact same thing with the rows, and you have the coin you need to flip!

There's a huge wall of text, but I just went overboard with explanation. It's all the same concept of odd/even.

EDIT 5: The assumption is simple to account for. If it starts odd, flip, in your head, the top left coin as well to make it start even.

46 Upvotes

52 comments sorted by

8

u/briseymo1 Jun 28 '15

Does the devil also tell my friend which coin is the magic coin?

Edit: Wow. I'm dumb. I read your scenario thoroughly and still asked this question. My bad!

3

u/bowj Jun 28 '15

My guess is you look at the 4 coins above, below, and next the magic coin. Since there is 4 coins around the magic coin there are 16 possibilities (2x2x2x2). Theres a 50% chance that the magic coin either has 3 heads or 3 tails next to it and theres only a 12.5% chance it has either 4 heads or 4 tails next to it. So I would flip the odd coin to match the other coins and tell my friend to pick the center coin. It's not a sure way, and it only works is the magic coin isn't on the side of the chessboard.

1

u/OddOliver Jun 28 '15

There is a solution which is non-probabilistic. Please use spoilers!

7

u/ShadeFinale Jun 28 '15

If you want a nice explanation to this puzzle you can look at this:

http://datagenetics.com/blog/december12014/index.html

(Which I think is the same puzzle but re-worded.)

1

u/OddOliver Jun 28 '15

Note: this is a really difficult puzzle, but very gratifying when you get it.

5

u/Swag-O Jun 28 '15

Could you post the solution in a spoiler tag please?

1

u/possumman Jun 28 '15 edited Jun 29 '15

1

u/OddOliver Jun 28 '15 edited Jun 28 '15

Yes, you only effectively need a binary number of length 6 to point to any square. However, this is impossible with only one flip, since the initial faces are random. What if they're all heads? Then you can only point to a large subset of the possible positions.

If you want a hint, try a simpler scenario: a 2x2 chessboard with only 4 coins. Can you find a way to point to an arbitrary square?

Lastly, please use spoilers, even if you're just guessing!

1

u/andraflandra Jun 28 '15

chess boards are 8x8

1

u/OddOliver Jun 28 '15

Yes, but you only effectively need a binary number of length 6 to point to any square. However, this is impossible with only one flip, since the initial faces are random. What if they're all heads? Then you can only point to a large subset of the possible positions.

1

u/DeDodgingEse Jun 28 '15

I don't see any solution possible! I guess I'm bad at this. Please post solution as a spoiler?

1

u/OddOliver Jun 28 '15

I'll post it, but I also want people to sweat a little :)

Also, I'm posting a hint.

1

u/xenopunk Jun 28 '15

Just a few questions before I start, Does it work 100% of the time? Is it a cheat? (i.e I put the coin sideways)

1

u/OddOliver Jun 28 '15

Yes, it works 100% of the time. It is not a cheat, straight logic. I just updated the post with a hint.

1

u/Desperoth Jun 28 '15

Are we allowed to rotate a coin when flipping it over?

1

u/OddOliver Jun 28 '15

Nope! Well, you could, I guess, but the other coins are randomly rotated as well. Nice thought, though! This is not a lateral thinking problem, more of a straightforward logic. See the hint spoiler in the original post!

1

u/sprite144 Jun 28 '15 edited Jun 28 '15

I've got a solution.

There are 18446744073709551616 different combinations. You make it so each combination corresponds to a space on the board. All 64 spaces have an equal amount of combinations. No matter what your board looked like and where the magic coin was you would be able to flip a coin to one of the 18446744073709551616 combinations to show which space the magic coin was on to your partner.

Only hard part is you have to remember 18446744073709551616 different combinations. : ^ )

1

u/OddOliver Jun 28 '15

That's not that hard, hahaha!

1

u/Cortye Jun 29 '15

After reading your solution, I still can't quiet figure out, how this is possible. I might read it wrong, but there seems to be a huge contradiction with you saying the field is layed out randomly and your assumptions. Maybe it's the language barrier I'm struggling with.

1

u/xenopunk Jul 06 '15

While possible I dislike the wording of this scenario, the method isnt really feasible for the given situation. Maybe with practice it would be but it seems it would require a computer to help you.

1

u/OddOliver Jul 06 '15

Not true. All you have to do is add up each column and each row. That's all you need for the calculations.

1

u/TLDM I like recreational maths puzzles Jul 06 '15

Finally looked at the answer. Wow. This is an amazing problem. Thank you for posting this.

1

u/OddOliver Jul 07 '15

=] I'm glad you liked it!

3

u/str8nwheel Jun 29 '15

i thought you could hold the coin long enough for it to warmth and then tell your friend to hurry and find it before it gets cold again :) thats not math though

1

u/NonstandardDeviation Jun 29 '15 edited Jun 29 '15

I personally think your visual explanation is more confusing, because it obscures the mathematical properties underlying your ability to encode information into the board. Nevertheless, it's a fun puzzle. Here's my solution, in python. http://pastebin.com/Wkxf3xB3

In short, you need to transmit to your friend 6 bits of information, about which of the 64=26 places on the board the coin could be in. The key to this is to look at the parity of various orthogonal slices of the board, which is also probably better understood as nothing more than a string of 64 booleans or 1s or 0s.

How could you transmit 1 bit of information on a 2-square board? Simple idea: if you want to transmit a '1' ('True'), look at the first coin and make sure it's heads up by flipping it if it's tails, or dumping your flip on the second coin if it's already heads. You transmit your information by setting it to be heads or tails for 1 or 0 (true or false), and if you don't need to flip it because it already matches, dump your flip on the other square.

That's the second bit, which you define to be '1' if the left column sums odd, '0' even, just like the rows. The same logic applied here dictates the column, and between the two you get a unique square to flip.

For any board (sequence) of size 2n, you slice the board n different ways for parity, and the n halvings decide for you which you flip. The key to the slices is by extending the idea of top and left of the 2-d square into more dimensions, or to be more mundane to just think about it as evenness, 4-ness, 8-ness, e.g. 10101010, 11001100, 11110000. Those are the 3 'slicings' of an 8-board, where the 2-board of the first example has 1 slicing, '10', and the 4-board has 2, '1100', '1010'. I found myself thinking about the slicing as looking something like a Haar, Fourier, or Hadamard matrix, but haven't found a name for exactly this. I definitely thought about this in terms of linear algebra, where my python 'friend' function to recover the information from the board can be thought of as performing a matrix multiplication. The board is a size-64 vector over GF(2), the finite field of 2 elements, and the bit-recovery matrix is a 6x64 matrix. I don't feel like typing it out in full, but for a 4x4 16-board, it looks like:

1111111100000000
1111000011110000
1100110011001100
1010101010101010

If you prefer it on github, here's the implementation again: https://github.com/dtyi/Cute-Math/blob/master/devil_chessboard.ipynb

1

u/EntertainmentNo5501 Apr 12 '24

Alright, it's been 5 weeks now. Chessboard Problem spoilers ahead.

Consider a vector space over GF(2) and the following linear mapping of binary vectors of dimension 64 into binary vectors of dimension 6:

[0 1 0 1 0 1 0 1 0 1]

[0 0 1 1 0 0 1 1 0 1]

M = [0 0 0 0 1 1 1 1 0 ... 1]

[0 0 0 0 0 0 0 0 1 1]

[0 0 0 0 0 0 0 0 0 1]

[0 0 0 0 0 0 0 0 0 1]

Note that M contains 64 columns corresponding to the binary representations of the integers 0-63 and the columns are unique and closed under linear combinations. Next, given a binary vector, v, of dimension 64 that represents the board state set by the warden, construct the following matrix:

     v[1 1 1 ... 1 1] + I = A

The matrix V = v[1 1 1 ... 1 1] is 64 x 64 and has the board vector v for every column. Adding the identity matrix I results in each column of A corresponding to one of the possible states obtained by flipping a single square. The columns are unique since each is comprised of the vector v with a unique component "flipped".

Clearly MA gives a 6 x 64 matrix, T. If it can be shown that every column of A maps to a unique column of T then each column of T corresponds to a unique integer in the range 0-63, like M. The index of the square where the key is hidden will then correspond to one of these columns. Furthermore, the index of the column will indicate which column of A gives the answer when multiplied by M, thus indicating which square to flip.

For instance, if the key is hidden under square 10 (with 0 based indexing), and the 30th column of T (again with zero based indexing) is the binary representation of 10 ([0 1 0 1 0 0]T), then flipping square 30 will give the answer when the new board vector is multiplied by M.

So, to prove every column of A maps to a unique column of T, assume otherwise. Then there are two columns of A = V + I, ai, aj, i != j for which

      Mai = Maj ->  Mvi + Mei = Mvj + Mej

But vi = vj for all i, j, so       

      Mvi + Mei = Mvj + Mej     ->    Mvi + Mei = Mvi + Mej     ->    Mei = Mej

Notice that Mei is just the ith column of M and Mej is the jth column. Then

      Mei = Mej   ->    mi = mj

But by construction the columns of M are unique so this is a contradiction. The columns of T are therefore unique and it is always possible to find a column representing the square where the key is hidden and thus which coin to flip.

The prisoner doing the encoding must compute MA but then after the correct flip resulting in board vector u, the other prisoner just needs to compute Mu to reveal the answer.

And really the encoding prisoner only needs to compute Mv and then find which column of M adds to Mv to give the desired answer since T = M(V + I) = [Mv ... Mv] + M.

0

u/xavortm Jun 28 '15

Its not mentioned that you cant leave signs right? That means that you can put some saliva on your finger before turning

1

u/OddOliver Jun 28 '15

Correct. This is straight logic.

0

u/[deleted] Jun 28 '15

[deleted]

1

u/John_Q_Nippleton_III Jun 28 '15

Yea, this is pretty tough. It kinda reminds me of the 50 people in a line with black/white hats puzzle

1

u/TLDM I like recreational maths puzzles Jun 28 '15

(Assuming you're thinking of the same one I was,) I was trying to think of a solution similar to that, but I can't think of anything that will help in this situation, even after looking at the hint.

0

u/[deleted] Jun 28 '15

[deleted]

1

u/OddOliver Jun 28 '15

I told you it's a hard problem! I posted a partial solution if you want, but in sections, so you can stop wherever you want.