# Sunday post with tasks

Hi, Habr.

The idea is this: many of us love to break our heads in our free time. And many people know many interesting puzzles. So why not share all this belongings?

I’ll probably start by assembling the tasks that I love, first with interviews, sometimes from friends, sometimes just picked up somewhere. Please supplement in the comments.

I tried, where possible, to separate the answer and the decision. So that you do not inadvertently spoil the buzz from solving the problem.

PS. Some of these tasks are VERY well-known, but nevertheless, the number of times that I come across them obliges me to write them as well.

Chased?

Task 1: The Liar Paradox (where without it?). She is very unpretentious, as many, of course, know. But a post about tasks without it would be incomplete.
Condition

You walked along the road for a long time and now you finally arrived at your goal. Before you are two doors. And you know for sure that for one treasure that you have been looking for so long, and for another a long and painful death. Two people are sitting in front of the door. You know for sure that one of them always tells the truth, and the other always lies. You also know for sure that they both know exactly what door is behind. And they also know exactly which of them is who. And, of course, both of them are sure that you came here just for the treasure.
Question:
What is one question to ask and to whom, in order to open the right door for sure?

Answer: “Which door will the other two of you tell me to open?”

Decision
Solution:
Initially, it is clear that it makes no difference which of the two to ask. We approach anyone and ask the question from the answer. Consider two options:
- If it so happened that we approached the liar, then he will think that the other will say the right door and point you to the other, since he always lies. As a result, you get the wrong door.
- if it happened that we went to a truthful person, then he will also point you to the wrong door, since he will truthfully tell you that the other will lie.
As a result, whoever we ask, we will receive an indication of the wrong door. We can only open another and enjoy the treasures.

Task 2: In the original “Togglers”. Let's call them "Defectors." A somewhat extended puzzle about liars.
Condition

Before us is five people. Four of them are “defectors”. Who are these "defectors"? Everything is very simple. If any of them, independently of the others, ask questions, then with each following, he will change his answers from false to true and vice versa.
We do not know in what "mood" they are initially. But we know for sure that if they once answered the truth, then the next time they will lie, and vice versa - if they lied the first time, then they will certainly tell the truth.
But one of these five is not a "defector." He always tells the truth.
Question:
How to find this fifth one, who always tells the truth, if only two questions are possible, and each one to only one?

can ask a question, as in the previous task, to any of them. We ask both questions to the same person.
"Do you always tell the truth?"
Further:
- if we received the answer “Yes”, then our next question will be “Who always tells the truth?”
- if we received the answer “No”, then our next question will be “Who is the“ defector “?”

Decision
Solution:
After the first question, we can get the answer “Yes” and “No”. Consider what this gives us:
- “Yes” means that we either hit a person who always tells the truth, or we hit a lying “deserter”. Thus, the following answer will be exactly true, which means if we ask, "Who always tells the truth?" they will point us to the right person.
- “No” means that we have fallen for the true “defector”. And this means that he will surely lie the next time. So our question is: “Who is the“ deserter? ”, He will have to point out to us the only non-“ deserter ”among this remarkable five.

Task 3: About the boxes with tablets
Condition

Before us are three boxes with apples, pears and in the third there are apples and pears. On all boxes there are wonderful signs: "Apples", "Pears", "Apples and Pears."
But the trouble is: the plates are messed up, and as usual, it’s dark in the drawers, nothing is visible, and we can only stick our hand into the hole and get something out of the drawer.
Question: What is the smallest amount of fruit you need to get and where to put the plates correctly again, if we know that all the boxes now have the wrong signs.

It is enough to get one fruit from a box on which the plate "Apples and Pears"

Decision
Solution:
Since we know that the tablets are incorrect, this box contains either apples or pears. Let's say we got an apple. Then we remove the “Apples” plate from the box on which it hangs and hang it instead of the “Apples and Pears” plate. Now we have a box on which the wrong plate “Pears” flaunts and we have in our hands the plate “Apples and Pears”. Now the tipping point. How to figure out where to hang what? Very simple. We use the condition that we know that ALL plates hang incorrectly, which means we hang the Pears plate on the box on which “Apples” was written at the very beginning, because this plate can not remain in its place. And we hang the plate "Apples and Pears" on the only free place.

Task 4: About the cake and the shameless bird
Condition

My grandmother had two grandchildren who were supposed to come to stay for the weekend. She, like any respectable grandmother, prepared a cake for them (very tasty). And put it on the windowsill. But while he was standing there, a shameless bird flew over his grandmother's house. And it so happened that she fulfilled her need exactly on the edge of the cake. Grandmother, seeing this, did not lose heart and decided that she would just cut out this piece (see picture). My grandmother was very fair, loved her grandchildren equally, and was anxious about her work. Help Grandma divide the whole remaining cake into two completely identical parts.
The grandmother has an ideal eye, she is easily able to find the middle and intersection of any segments on her eye. And the grandmother has a wonderful knife (from German steel), with which she knows how to famously cut pieces of cake on any intended straight line.
Question:
What is the minimum number of cuts a grandmother needs to make to cut a cake?
(Clarification, this is a cake, not a cake. It cannot be cut horizontally, since then one of the grandchildren will have to be content with only the cream)
After cutting a piece of cake, it looks like this:

Decision
Solution:
All lines passing through the center of the rectangle divide its area exactly in half.

Task 5: About the ladder (a more complex version of this task was already on Habr, here )
Condition

Ten prisoners will be put on the stairs tomorrow so that everyone will look in the back to the one who stands below. Thus, he will see everyone who stands before him. Hats will be worn on them all. The hats will be either black or white. Of course, none of them will see the color of their caps. The hats will be distributed randomly - they can be all black, they can all be white, or they can be mixed. This will be decided by the custodians of the prison on the spot.
Further, the caretakers go down the stairs and ask everyone: "What color is your hat?" If he answers correctly, he is released. If mistaken - they kill.
Question:
Prisoners have a whole night to come up with a strategy for behavior. Help them guaranteed to save as many people as possible.

Prisoners must choose some color. Let it be black. Then the top prisoner, number 10, should count the hats in black. Then he should say “black” if there were an even number of black caps, and “white” if there was an odd number of black caps. His life, of course, is not guaranteed. He may be lucky, but may not be lucky.
That prisoner, under him, number 9, must compare what he sees with what the previous one said. Let's say the first one said “black”. Then there are two options:
- number 9 sees an even number of black hats. Then he says “white”, because the number of black hats remains the same, which means it is white. This gives the number 8 information that there are an even number of black caps.
- number 9 sees an odd number of black hats. This means that he himself is under a black hat. Then he says “black” and number 8 understands that now there are an odd number of black hats.
Etc. Thus, we are guaranteed to save as many as nine hardened prison lives.

Task 6: The task of the gnomes in hats:
Condition

In the cave live 100 gnomes. Once, Snow White, who, of course, lives with them, became bored and she tied all the gnomes with colorful hats that they wear with pleasure. Of course they, at the same time, do not know what color the hat is wearing, since Snow White wore them in pitch darkness.
Moreover, gnomes are rather apathetic creatures. All they do in the cave is sit in a circle and look at each other. They don’t even talk and do not lead any social life. They just sit, look and think about something. Each gnome sees the remaining 99 gnomes. Accordingly, everyone sees all the hats of all the dwarves, except his own. Every day, Snow White, so as not to lose her beloved dwarves, leads them to the building in front of the cave. And every time she tells them: “Whoever is in the blue hat is out of order.” Dwarves who are 100% sure that they will have a blue hat on after that will take a step forward. If the gnome believes that his hat may be of a different color, he will remain standing rooted to the spot. To avoid confusion, we add the fact that those gnomes who are out of order are transferred to another cave. To judge
Question:
What will happen at the building, on what day, and why, if we know these three things:
- Snow White, from boredom, put blue hats on all gnomes.
“Snow White told the gnomes that there was at least one gnome in a blue hat.”
- Gnomes, for many years of life in a cave, have honed their logic to perfection. She is infallible. And each of them understands that all other gnomes have the same infallible logic.

99 days nothing will happen, for the hundredth, all dwarves will take a step forward.

Decision
Solution:
Consider the situation not with a hundred gnomes, but something simpler, say with one gnome.
He sits in the room all day and does not see anyone. Since he knows that there must be at least one gnome in a blue hat, then at the first construction he will take a step forward, as he will be 100% sure of the color of his hat.
Now consider the option when the gnome is two. They sit all day in a cave and look at each other. What do they see?
They see a gnome in a blue cap sitting opposite. Now they are not sure of the color of their hats, because they know that there must be at least one gnome in a blue hat and they just see him in front of them. But what would happen if one of them saw on the other not a blue hat, but, say, a red one? This would lead him to logic from the previous step, where we had one gnome. So he would go out on the first build.
When the gnomes see that this did not happen and they both remained standing rooted to the ground (since in our case they both see the blue hat opposite themselves), each of them immediately understands, knowing that each gnome has an infallible logic, that, if the other gnome had not seen the blue hat on himself, that gnome would have come forward at the first construction. The fact that this did not happen is sufficient for both gnomes to become confident in the color of their caps and, therefore, they will come out together on the second day.
The same logic easily extends to an arbitrary number of gnomes.

Condition

In two identical glasses, the same amount of different liquid is poured . In one is wine, in the other is water (in this problem we assume that there is no water in the wine).
We collect a full teaspoon of wine from a glass, in fact, with wine and pour into water. Mix thoroughly and scooping up the same full teaspoon of what happened, pour it back into a glass of wine.
Question:
What is more - water in wine or wine in water?

Equally

Decision
Solution:
Let there be 8 units of wine in the first glass (glass 1) and 8 units of water in the second glass (glass 2). Let the spoon contains 2 units of liquid. After we poured a teaspoon of wine from glass 1 into glass 2 we get: a
glass of 1: 6 units of wine a
glass of 2: 8 units of water + 2 units of wine
After mixing, we take a teaspoon of what came out of glass 2. B this spoon, the proportions of liquids are the same as in the glass itself. Namely:
water: 0.8 * 2 = 1.6
wine: 0.2 * 2 = 0.4
After pouring this teaspoon back into a glass of wine: a
glass of 1: 6.4 units of wine + 1.6 units of water a
glass of 2: 6.4 units of water + 1.6 units of wine

Task 8: About a series of light bulbs. (thanks nullbie for the task )
Condition

In a row are 100 bulbs.
Near each there is a button that switches the state of the bulb to the opposite, that is, if the bulb was on, then after pressing the button, it will be turned off. And vice versa.
A line of one hundred people is let go past the light bulbs. The first presses the button of each light bulb, the second presses the button of every second, the third presses the button of every third, and so on.
Question:
What bulbs will burn after the passage of these 100 people, if initially all were turned off.

1 4 9 16 25 36 49 64 81 100

Decision
Solution: The
lamp is switched by those people whose serial number is a divider of the number of the lamp. Therefore, the light bulb will remain on if and only if there is an odd number of divisors in its serial number. Typically, dividers "walk" in pairs. For example, for the number 8:
8 = 1 * 8
8 = 2 * 4
That is, in this case, for the bulb with number 8 - the first person turns it on, the second turns it off, the fourth turns it on and the eighth turns off.
The only numbers with an odd number of divisors are full squares, for example 9:
9 = 1 * 9
9 = 3 * 3
Thus, the number 9 has 3 different divisors, which means that the light with this number will remain on. Similarly for all other full squares.

Task 9: The task of the area.
Condition

28

Decision
Solution:
Draw a line EF, which will be parallel to lines AB and CD (point D below, it was accidentally cut off). Now, if we move point O to point T (intersection of green lines), then the area of ​​the triangles will not change. Then everything is simple. If someone comes up with another solution, I will be glad to hear it, because mine looks a bit like a crutch. I apologize for the quality of the picture, only the phone is at hand.

Decision 2
Solution 2: Thanks for it. Xitsa
Draw additional lines from point to corner. After that, existing ones will become medians of triangles. As you know, the median divides the area of ​​the triangle in half:

Hence the equations:
a + d = 32
a + b = 20
b + c = 16
And we easily get c + d = 32 + 16-20 = 28

Decision 3
Solution 3: thanks for it oleg1977
let 2a be the side of the square, from O we omit the heights x, y, (2a-x) and (2a-y).
Further, the system of equations (the area of ​​4-gons from the areas of 3-gons):
ax / 2 + ay / 2 = 20,
ay / 2 + a (2a-x) / 2 = 16
ax / 2 + a (2a-y) / 2 = 32

ax / 2 -a (2a-x) / 2 = 4
ay / 2 -a (2a-y) / 2 = -12
ax / 2 + ay / 2 = 20

ax = a ^ 2 + 4
ay = a ^ 2 - 12
a ^ 2 + 2 - 6 = 20

Seeking: a (2a-x) / 2 + a (2a-y) / 2 = 2a ^ 2 - ax / 2 - ay / 2 = a ^ 2 - 2 + 6 = 24 - 2 + 6 = 28

Task 10: Prisoners and a light bulb
Condition

There are 100 prisoners in jail. The overseers wanted, as always, to have fun and they came up with the following "game." The prisoners are going in arbitrary order with arbitrary frequency to drive into a room where there is only a light bulb and a switch to it. The overseers also select one of the prisoners (the responsible prisoner), who, at each visit to the cell with a light bulb, asks if all of these 100 prisoners have been in the cell. He may say that he is not sure any number of times. But, if he says that, they say, yes, everyone has been, then the following happens. If he was not mistaken, everyone is released, and if he is mistaken, then, as usual, they execute him.
Question:
Prisoners have a night to come up with a cunning plan of how to escape. Help them develop their strategy. The light is initially off.

Prisoners must agree that the one who is selected to be responsible for all should always turn on the light bulb when he enters the room with her. All the rest should turn it off, but touch it only once. That is, if the prisoner turned off the bulb once once, then he doesn’t touch it anymore, no matter in what condition he finds it, when he enters the room. The responsible prisoner must count the number of times he had to turn on the light bulb. As soon as he got 100, he can confidently say that all the prisoners have been in the room.

Task 11: The task of the magician and the card. (I don’t remember where I got it, but decided when I was in line for 4 hours waiting for a new birth certificate. I didn’t decide :) ( UPD : The task caused a lot of excitement, added clarifications to the condition and a new solution for the condition that was originally)
Condition

The magician takes a standard deck of 52 cards, and gives it to the audience. Viewers choose (in any way) any 5 cards and give them to the assistant magician. He looks at the cards and calls the magician 4 of them. In response, the magician calls the fifth. In addition to the suits and values ​​of the cards, the magician does not receive any additional information (the assistant speaks in an even voice, without pauses, etc.) ( Clarification: it was understood that the assistant does not tell the magician anything but the suit and name of the cards) .
Question:
How does a magician manage to “guess” the fifth card?

The answer and solution for the option with clarification:
The assistant received 5 cards from the audience. Since there are only 4 card suits, then at least 2 cards have the same suit. This suit will be guessed by a magician. The first card that the assistant calls will have the same suit as the card that the magician will need to guess (the assistant has the right to choose which card to not name). With the suit sorted out. To find out the type of card, the famous binary system works. Since there are only 13 different cards in the deck, and the assistant will call 4 cards with 4 cards being 4 bits, then using 4 bits you can display the maximum number 1111, which in the decimal system is 1 * 2 ^ 3 + 1 * 2 ^ 2 + 1 * 2 ^ 1 + 1 * 2 ^ 0 = 1 * 8 + 1 * 4 + 1 * 2 + 1 = 8 + 4 + 2 + 1 = 15, that is, it is quite enough for the image of 13 cards. Let 2 = 2,3 = 3,4 = 4 ... 10 = 10, jack = 11, queen = 12, king = 13, ace = 14. Now for the designation “1” the card is called “suit first,

Answer and solution for the option without specification:
First, select two cards of the same suit. Let their values ​​be x and y (modulo 13). We compute the difference xy. If (x-y + 13)% 13> 6, then postpone the card x, otherwise we postpone y. We will name the second of these cards. It determines the suit of the hidden card and the range of 6 value options. So, if we called volta peak, then only the queen, king, ace, deuce, three or four spades can be a hidden card.
There are three cards left that need to encode one of the 6 options. We agree in advance about some function of comparing cards in the deck, after which 6 options are encoded in the order in which we call these three cards. If the remaining cards A, B, C, where A <B <C, then hearing the sequence X, A, B, C, the magician will call X + 1, hearing X, A, C, B - X + 2, ..., and on X, C, B, A will say X + 6.

And finally, for the mood,
Task 12: About the looking cow (for children)
Condition
Meet this cow. She is looking.

Question:
How, by shifting 2 matches, can you make a cow look the other way?