Logic Puzzles


1. The Emperor

You are the ruler of a medieval empire and you are about to have a celebration tomorrow. The celebration is the most important party you have ever hosted. You've got 1000 bottles of wine you were planning to open for the celebration, but you find out that one of them is poisoned.

The poison exhibits no symptoms until death. Death occurs within ten to twenty hours after consuming even the minutest amount of poison.

You have over a thousand slaves at your disposal and just under 24 hours to determine which single bottle is poisoned.

You have a handful of prisoners about to be executed, and it would mar your celebration to have anyone else killed.

What is the smallest number of prisoners you must have to drink from the bottles to be absolutely sure to find the poisoned bottle within 24 hours?

Hint:
It is much smaller than you first might think. Try to solve the problem first with one poisoned bottle out of eight total bottles of wine.

Solution:
10 prisoners must sample the wine. Bonus points if you worked out a way to ensure than no more than 8 prisoners die.

Number all bottles using binary digits. Assign each prisoner to one of the binary flags. Prisoners must take a sip from each bottle where their binary flag is set.

Here is how you would find one poisoned bottle out of eight total bottles of wine.

  1 2 3 4 5 6 7 8
Prisoner A   X   X   X   X
Prisoner B     X X     X X
Prisoner C         X X X X

In the above example, if all prisoners die, bottle 8 is bad. If none die, bottle 1 is bad. If A & B dies, bottle 4 is bad.

With ten people there are 1024 unique combinations so you could test up to 1024 bottles of wine.

Each of the ten prisoners will take a small sip from about 500 bottles. Each sip should take no longer than 15 seconds and should be a very small amount. Small sips not only leave more wine for guests. Small sips also avoid death by alcohol poisoning. As long as each prisoner is administered about a millilitre from each bottle, they will only consume the equivalent of about one bottle of wine each.

Each prisoner will have at least a fifty percent chance of living. There is only one binary combination where all prisoners must sip from the wine. If there are ten prisoners then there are ten more combinations where all but one prisoner must sip from the wine. By avoiding these two types of combinations you can ensure no more than 8 prisoners die.

One viewer felt that this solution was in flagrant contempt of restaurant etiquette. The emperor paid for this wine, so there should be no need to prove to the guests that wine is the same as the label. I am not even sure if ancient wine even came with labels affixed. However, it is true that after leaving the wine open for a day, that this medieval wine will taste more like vinegar than it ever did. C'est la vie.

 


2. The Stark Raving Mad King

A stark raving mad king tells his 100 wisest men he is about to line them up and that he will place either a red or blue hat on each of their heads. Once lined up, they must not communicate amongst themselves. Nor may they attempt to look behind them or remove their own hat.

The king tells the wise men that they will be able to see all the hats in front of them. They will not be able to see the color of their own hat or the hats behind them, although they will be able to hear the answers from all those behind them.

The king will then start with the wise man in the back and ask "what color is your hat?" The wise man will only be allowed to answer "red" or "blue," nothing more. If the answer is incorrect then the wise man will be silently killed. If the answer is correct then the wise man may live but must remain absolutely silent.

The king will then move on to the next wise man and repeat the question.

The king makes it clear that if anyone breaks the rules then all the wise men will die, then allows the wise men to consult before lining them up. The king listens in while the wise men consult each other to make sure they don't devise a plan to cheat. To communicate anything more than their guess of red or blue by coughing or shuffling would be breaking the rules.

What is the maximum number of men they can be guaranteed to save?

Hint:
To solve this problem, you need to presume that each wise man can count the total number of red hats in front of them without error, that all the wise men have great attention to detail and that all the wise men care about the greater good.

Solution:
99.

You can save about 50% by having everyone guess randomly.

You can save 50% or more if every even person agrees to call out the color of the hat in front of them. That way the person in front knows what color their hat is, and if the person behind also has the same colored hat then both will survive.

So how can 99 people be saved? The first wise man counts all the red hats he can see (Q) and then answers "blue" if the number is odd or "red" if the number is even. Each subsequent wise man keeps track of the number of red hats known to have been saved from behind (X), and counts the number of red hats in front (Y).

If Q was even, and if X&Y are either both even or are both odd, then the wise man would answer blue. Otherwise the wise man would answer red.

If Q was odd, and if X&Y are either both even or are both odd, then the wise man would answer red. Otherwise the wise man would answer blue.

There can be any number of red hats, as the following examples show...

Prisoner Hat he wears Number of red hats he sees (Y) Red hats saved for sure (X) He says
1 red 6 even (Q)  

N/A

red
2 blue 6 even 0 even blue
3 red 5 odd 0 even red
4 blue 5 odd 1 odd blue
5 blue 5 odd 1 odd blue
6 red 4 even 1 odd red
7 red 3 odd 2 even red
8 red 2 even 3 odd red
9 red 1 odd 4 even red
10 red 0 even 5 odd red

Another example might also help, as this puzzle seems to trip up most people...

Prisoner Hat he wears Number of red hats he sees (Y) Red hats saved for sure (X) He says
1 blue 5 odd (Q)   N/A blue
2 blue 5 odd 0 even blue
3 red 4 even 0 even red
4 blue 4 even 1 odd blue
5 blue 4 even 1 odd blue
6 red 3 odd 1 odd red
7 blue 3 odd 2 even blue
8 red 2 even 2 even red
9 red 1 odd 3 odd red
10 red 0 even 3 odd red

 


3. The Fake Coin

You have twelve coins. You know that one is fake. The only thing that distinguishes the fake coin from the real coins is that its weight is imperceptibly different. You have a perfectly balanced scale. The scale only tells you which side weighs more than the other side.

What is the smallest number of times you must use the scale in order to always find the fake coin?

Use only the twelve coins themselves and no others, no other weights, no cutting coins, no pencil marks on the scale. etc.

These are modern coins, so the fake coin is not necessarily lighter.

Presume the worst case scenario, and don't hope that you will pick the right coin on the first attempt.

Hint:
The balance tells you which side is heavier and which side is lighter. You can move coins around and get more information this way.

Solution:
3.

If you knew the fake coin was lighter, then the solution would have an easy explanation. But you do not. So....

Number the coins 1 through 12.

1. Weigh coins 1,2,3,4 against coins 5,6,7,8.

1.1. If they balance, then weigh coins 9 and 10 against coins 11 and 8 (we know from the first weighing that 8 is a good coin).

1.1.1. If the second weighing also balances, we know coin 12 (the only one not yet weighed) is the counterfeit. The third weighing indicates whether it is heavy or light. 

1.1.2. If (at the second weighing) coins 11 and 8 are heavier than coins 9 and 10, either 11 is heavy or 9 is light or 10 is light. Weigh 9 against 10. If they balance, 11 is heavy. If they don't balance, you know that either 9 or 10 is light, so the top coin is the fake.

1.1.3 If (at the second weighing) coins 11 and 8 are lighter than coins 9 and 10, either 11 is light or 9 is heavy or 10 is heavy. Weigh 9 against 10. If they balance, 11 is light. If they don't balance, you know that either 9 or 10 is heavy, so the bottom coin is the fake. 

1.2. Now if (at first weighing) the side with coins 5,6,7,8 are heavier than the side with coins 1,2,3,4. This means that either 1,2,3,4 is light or 5,6,7,8 is heavy. Weigh 1,2, and 5 against 3,6, and 9.

1.2.1. If (when we weigh 1,2, and 5 against 3,6 and 9) they balance, it means that either 7 or 8 is heavy or 4 is light. By weighing 7 and 8 we obtain the answer, because if they balance, then 4 has to be light. If 7 and 8 do not balance, then the heavier coin is the counterfeit. 

1.2.2. If (when we weigh 1,2, and 5 against 3,6 and 9) the right side is heavier, then either 6 is heavy or 1 is light or 2 is light. By weighing 1 against 2 the solution is obtained.

1.2.3. If (when we weigh 1,2, and 5 against 3, 6 and 9) the right side is lighter, then either 3 is light or 5 is heavy. By weighing 3 against a good coin the solution is easily arrived at.

1.3 If (at the first weighing) coins 1,2,3,4 are heavier than coins 5,6,7,8 then repeat the previous steps 1.2 through 1.2.3 but switch the numbers of coins 1,2,3,4 with 5,6,7,8.


4. The Trainee Technician

A 120 wire cable has been laid firmly underground between two telephone exchanges located 10km apart.

Unfortunately after the cable was laid it was discovered to be the wrong type, the problem is the individual wires are not labeled. There is no visual way of knowing which wire is which and thus connections at either end is not immediately possible.

You are a trainee technician and your boss has asked you to identify and label the wires at both ends without ripping it all up. You have no transport and only a battery and light bulb to test continuity. You do have tape and pen for labeling the wires.

What is the shortest distance in kilometers you will need to walk to correctly identify and label each wire?

Hint:
Creating a single loop will only help you identify all the wires by walking 40km. You need to group them in a rather odd matrix.

Solution:
20.

At one end label a wire "A". Then join two wire and label them both "B', then tie three (not already joined) wires together and call them each "C"....continue until all the wires are joined together in groups of 1, 2, 3, 4, 5, etc....for a 120 strand cable. NOTES that the largest group will have 15 wires.

Now walk to the other end.

Using a (battery and light bulb) it is now possible, for example, to find the wire that wasn't joined to any of the others. It is similarly possible to find which wires are in a pair, which is joined in a group of 3, etc. Each time a group is found the technician should label it with the letter for the group, so the single wire is labeled 'a', the pair are each labeled "A", etc....this now matches the other end.....the letters will go up to "O". Now take "A", "B", up to "O" and join them together in a group and label each one with "15", so we have cable "A15", "B15', "C15", up to "O15". Take the second and last "B'"wire and 
join it with a remaining "C", "D", up to "O" and label these each "14' so we have "B14", "C14", up to "O14". Repeat this until at the end there will be a single "O" cabled labeled "O1".

Now walk to the other end.

Now untie all the old connections and identify the group labeled "1", "2", "3" ..."15" at which point each wire at each end has a unique classification.

Alternative solution from citrog:

First, tie the 120 wires together randomly in 60 pairs. Next, go to the far end, randomly label any wire 1, and connect the battery to it. Test which other wire is tied to it at the starting end, and label that wire 2. Then pick another wire other than 1 or 2, label it 3, and tie it to 2, so now the battery is connected to 1, which is tied to 2 at the other end, which is tied to 3 at the end you're at. Now test which wire is tied to 3 at the other end, and label that 4, etc. What you will wind up with is all 120 wires tied to each other in a continuous sequence. Then go back to the end you started at, leaving the battery behind, connected to wire 1. Before you untie all the wires at the starting point, label each wire so that you know which wire was paired with which. Now with all the wires untied at the starting point, test which wire is connected to the battery, and label that 1. Whichever wire was in the same pair as 1, label that 2, and then tie 1 and 2 back together. Now you can find 3, because it's tied to 2 on the far end. Once you find 3, label the wire it was tied to 4, etc. This assumes that the resistance of the wire is small enough that the battery will still light the bulb across 12,000 km of wire.


5. The Card Trick

I ask Alex to pick any 5 cards out of a deck with no Jokers.

He can inspect then shuffle the deck before picking any five cards. He picks out 5 cards then hands them to me (Peter can't see any of this). I look at the cards and I pick 1 card out and give it back to Alex. I then arrange the other four cards in a special way, and give those 4 cards all face down, and in a neat pile, to Peter.

Peter looks at the 4 cards i gave him, and says out loud which card Alex is holding (suit and number). How?

The solution uses pure logic, not sleight of hand. All Peter needs to know is the order of the cards and what is on their face, nothing more.

Hint:
There are only 4 suits, so there will be at least two cards of one suit, one higher and another lower. By careful selection and placement the cards can be used to encode the exact number and suit of the selected card.

Solution:
Pick out two cards of the same suit. Select a card for Alex where adding a number no greater than six will result in the number of the other card of the same suit. Adding one to the Ace would cycle to the beginning again and result in a Two. E.g. if you have a King and a Six of Diamonds, hand the King to Alex. The other three cards will be used to encode a number from 1 through 6. Devise a system with Peter to rank all cards uniquely from 1 to 52 (e.g. the two of hearts is 1, the two of diamonds is fourteen etc...). That will allow you to choose from six combinations, depending on where you put the lowest and highest cards. 


6. The Warden

The warden meets with 23 new prisoners when they arrive. He tells them, "You may meet today and plan a strategy. But after today, you will be in isolated cells and will have no communication with one another.

"In the prison is a switch room, which contains two light switches labeled 1 and 2, each of which can be in either up or the down position. I am not telling you their present positions. The switches are not connected to anything.

"After today, from time to time whenever I feel so inclined, I will select one prisoner at random and escort him to the switch room. This prisoner will select one of the two switches and reverse its position. He must flip one switch when he visits the switch room, and may only flip one of the switches. Then he'll be led back to his cell.

"No one else will be allowed to alter the switches until I lead the next prisoner into the switch room. I'm going to choose prisoners at random. I may choose the same guy three times in a row, or I may jump around and come back. I will not touch the switches, if I wanted you dead you would already be dead.

"Given enough time, everyone will eventually visit the switch room the same number of times as everyone else. At any time, anyone may declare to me, 'We have all visited the switch room.'

"If it is true, then you will all be set free. If it is false, and somebody has not yet visited the switch room, you will all die horribly. You will be carefully monitored, and any attempt to break any of these rules will result in instant death to all of you"

What is the strategy they come up with so that they can be free?

Hint:
Take a long-term perspective. Solve the puzzler for three prisoners.

Solution:

The team nominates a leader. The group agrees upon the following rules:

The leader is the only person who will announce that everyone has visited the switch room. All the prisoners (except for the leader) will flip the first switch up at their very first opportunity, and again on the second opportunity. If the first switch is already up, or they have already flipped the first switch up two times, they will then flip the second switch. Only the leader may flip the first switch down, if the first switch is already down, then the leader will flip the second switch. The leader remembers how many times he has flipped the first switch down. Once the leader has flipped the first switch down 44 times, he announces that all have visited the room.

It does not matter how many times a prisoner has visited the room, in which order the prisoners were sent or even if the first switch was initially up. Once the leader has flipped the switch down 44 times then the leader knows everyone has visited the room. If the switch was initially down, then all 22 prisoners will flip the switch up twice. If the switch was initially up, then there will be one prisoner who only flips the switch up once and the rest will flip it up twice.

The prisoners can not be certain that all have visited the room after the leader flips the switch down 23 times, as the first 12 prisoners plus the leader might be taken to the room 24 times before anyone else is allowed into the room. Because the initial state of the switch might be up, the prisoners must flip the first switch up twice. If they decide to flip it up only once, the leader will not know if he should count to 22 or 23.

In the example of three prisoners, the leader must flip the first switch down three times to be sure all prisoners have visited the room, twice for the two other prisoners and once more in case the switch was initially up.


Translated by Unknown.

Puzzles