Pure maths, physics, logic (braingames.ru): non-trade-related brain games - page 213

 

A problem for programmers (weight of the problem is 4):

A megabrain in a very long text needs to replace all the letters "A" with "B" and all the letters "B" with "A". The text editor allows one arbitrary set of characters to be replaced by another in the whole text. For example, replacing "AA"->"BSAA" will cause the string "AAAAAL" to become "BSAABSAAL". How does he complete the task?

FAQ (from the website):

Вы не знаете алфавита текстового редактора. Единственное, что вы знаете, это то, что он содержит символы "А" и "Б".

(Explanation from Mathemat: in the first field (WHAT to replace) and in the second (WHAT to replace) you can only use characters A and B and nothing else, not even spaces: the alphabet of the text and text editor is unknown to us. It is still unclear to me why this key clarification is missing from the text of the problem itself, but alas, it is).

The condition doesn't explicitly say this, but I take it that all other characters except A and B must remain unchanged. Is this correct?

Yes.

What does "very long text" mean?

1. You can't make all the substitutions manually.
2. Any given sequence of characters can occur in it.
3. the megabrain cannot use sequences with a length comparable to the length of the text for substitution.

Is there a character missing from the text in the text editor's "arsenal"?

No.

Is it possible to make multiple changes throughout the text?

Yes.

Can some sequences be skipped? For instance, replacing "AA"->"BSAA" will change the string "AAAAAL" to "BSAAAL" (i.e. the 2nd sequence was skipped).

No.

Can regular expressions (or their counterparts) be used when replacing?

No.

The solution of the problem shocked me by its unexpectedness (although other solutions are quite possible). I started solving it a couple of years ago, after which I disappeared from Mind Games for a year and a half. A couple of days ago I looked at it again, and about 24 hours ago sent the solution to a moderator. I haven't received a reply yet, but I'm 100 percent sure it's correct. The algorithm is tested on a test character set, no errors found.

Задачи, загадки, логические игры [Игры разума] икф
  • www.braingames.ru
Мегамозгу в очень длинном тексте требуется заменить все буквы «А» на буквы «Б», а все буквы «Б» - на буквы «А». Текстовый редактор позволяет заменить во всём тексте один произвольный набор символов на другой. Например, в результате замены «АА»->«БСАА» строка «АААААЛ» перейдёт в строку «БСААБСАААЛ». Как ему выполнить задачу?
 
Mathemat:

A problem for programmers (weight of the problem is 4):

A megabrain in a very long text needs to replace all the letters "A" with "B" and all the letters "B" with "A". The text editor allows one arbitrary set of characters to be replaced by another in the whole text. For example, replacing "AA"->"BSAA" will cause the string "AAAAAL" to become "BSAABSAAL". How can he do the task?

FAQ (from the website):

The solution to the problem just shocked me with its unexpectedness (although I'm quite open to other solutions). I started solving it a couple of years ago, after which I disappeared from the Mind Games for a year and a half. A couple of days ago I looked at it again, and about 24 hours ago sent the solution to a moderator. I haven't received a reply yet, but I'm 100 percent sure it's correct. The algorithm is tested on a test character set, no errors found.

Can't A->A, B->B, AA->B, B->A?
 
Avals:
Can't A->A, B->B, AA->B, B->A?


You can, but you can't.

For example, here's the text "AAAAAAAAAAAAAAAABBBBBBBBB", resulting in: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

 
Mathemat:

A problem for programmers (weight of the problem is 4):

A megabrain in a very long text needs to replace all the letters "A" with "B" and all the letters "B" with "A". The text editor allows one arbitrary set of characters to be replaced by another in the whole text. For example, replacing "AA"->"BSAA" will cause the string "AAAAAL" to become "BSAABSAAL". How does it solve the problem?

FAQ (from the website):

The solution to the problem just shocked me with its unexpectedness (although I'm quite open to other solutions). I started solving it a couple of years ago, after which I disappeared from Mind Games for a year and a half. A couple of days ago I looked at it again, and about 24 hours ago sent the solution to a moderator. I haven't received a reply yet, but I'm 100 percent sure it's correct. The algorithm is tested on a test character set, no errors found.

It is solved in 4 substitutions:

A -> AA

B -> BAB

AA -> B

BAB -> A

 
Contender:

Solved in 4 substitutions:

A -> AA

B -> BAB

AA -> B

BAB -> A

Didn't check, but this solution is given in the comments for those who have solved. Here is my solution:

A -> AB
B -> AB
AB -> B
AB -> A

Note: the first two substitutions (more precisely, their right-hand parts) are formally identical.

Can anyone do it in less than 4 moves?

-----------------------------------------------------------------------------

And by the way, what about this problem?

Задачи, загадки, логические игры [Игры разума] икф
  • www.braingames.ru
Перед вами на столе два тонкостенных непрозрачных сосуда кубической формы (без верхней грани) емкостью 4.096 и 8 литров. Как, имея неограниченный запас воды, быстро отмерить ровно 5 литров?
 
Mathemat:

In front of you on the table are two thin-walled opaque cube-shaped vessels (without a top edge) with capacities of 4.096 and 8 litres. With an unlimited supply of water, how can you quickly measure out exactly 5 litres?

The task is here. The weight of the problem is 5.

FAQ:

- the walls are very thin, their volume is negligible.

- 4.096 is four whole and ninety-six thousandths of a litre, exactly. Exactly 5 litres is exactly 5, not, say, 5.002 litres.

- Opacity means that you cannot, for example, put a smaller cube into a bigger one and pour water into the bigger one up to the edges of the smaller one. Because of the opacity, it cannot be done accurately enough.

- fast is really fast, quite fast. The ten-step decision will not be taken. It is too long.

It's a tricky one. I solved it in three steps.

1) Put a small cube in a large cube, and fill the large cube to the edges. Now tilt it so that the surface of the water touches the edge of the small cube. (if you have accidentally spilled too much water - give some more, it's a lot).


Now we have poured out exactly one litre of water. (The length of the segment AB=5 cm, it is easy to calculate from the size of the sides of the cubes (20cm and 16cm respectively).

Carefully take out the small cube, leaving all water (7 litres) in the big cube.

Now tilt the large cube until the water touches the "diagonal" edge (opposite to the edge through which the water is poured out), and pour the water into the small cube.

The large cube will hold exactly half its volume (4 litres); the small one will hold 3 litres (= 7 litres - 4 litres).

Now fill the big cube to the brim or a little less. Carefully put the small cube with three litres of water in it. Its volume is more than 3 litres, so it will not sink completely, but only just enough to displace 3 litres of water from the big cube. Now take out the small cube. The big cube has exactly five litres (8L - 3L), which was required.

 
Mathemat:

Didn't check, but such a solution is given in the comments for those who have decided. Here is my solution:

Note: The first two substitutions are formally identical.

Can anyone do it in less than 4 moves?

In three global substitutions the solution is possible only if there is an additional character present in the permissible alphabet, but guaranteed absent in the text, which by the condition of the problem is not.

In the given conditions four moves are minimal. It can be (but tediously and verbosely) proved. :)

 
MetaDriver:

It's a tricky one, I did it in three steps.

1) Place the small cube in the large cube, and fill the large cube up to the edge. Now tilt it so that the surface of the water touches the edge of the small cube. (if you have accidentally spilled too much water - give some more, it's a lot).


Now we have poured out exactly one litre of water. (The length of the segment AB=5 cm, it is easy to calculate from the size of the sides of the cubes (20cm and 16cm respectively).

Carefully take out the small cube, leaving all water (7 litres) in the big cube.

Now tilt the large cube until the water touches the "diagonal" edge (opposite to the edge through which the water is poured out), and pour the water into the small cube.

The large cube will hold exactly half its volume (4 litres); the small one will hold 3 litres (= 7L-4L).

Now pour the big cube to the brim or a little less. Carefully put the small cube with three litres of water into it. Its volume is larger than 3 litres, so it will not sink completely, but only just enough to displace 3 litres of water from the big cube. Now take out the small cube. The big cube has exactly five litres (8L - 3L), which was required.

so in the first step 2 litres are poured )

0.05*0.2*0.2=0.002 м3

 
sanyooooook:

so in the first step, 2 litres are poured)

0.05*0.2*0.2=0.002 м3

you're lying again ;)

the area of triangle ABC = (0.05*0.2) / 2

total: ((0.05*0.2) / 2) * 0.2 = 0.001 m^3

 
MetaDriver:

A tricky problem, I solved it in three steps.

1) Put a small cube in a big one, and fill the big cube up to the edges. Now tilt it so that the surface of the water touches the edge of the small cube. (if you have accidentally spilled too much water, give it a refill, it's a lot).

Original, but there seems to be a contradiction in opacity. And holding the big cube tilted without any support is not so easy, you need two people.

Now, we tilt the big cube until the water edge touches the "diagonal" edge (opposite to the edge through which the water pours out), and pour the water into the small cube.

And there's similar bullshit here, especially with pouring water into the small one. Pouring water from the big one into the small one through the edge of the big one is difficult without special devices.

In short, there is a shorter and simpler solution :)

MD: For three global substitutions the solution is possible only if there is an additional character that is present in the valid alphabet, but guaranteed absent in the text, which by the terms of the problem is not the case.

In these conditions four strokes are minimum. It can be proved (but tediously and verbosely). :)

Moderators claim that no one at the Mind Games has yet provided a solution shorter than 4 moves. (I didn't propose the problem below, it's just an automaton of our site's engine.)

Задачи, загадки, логические игры [Игры разума] икф
  • www.braingames.ru
У Мегамозга нашли страшную болезнь. Доктор выписал ему всего 4 таблетки двух видов (по две каждого вида), совершенно не отличимых друг от друга, и предупредил, что, если выпить более одной таблетки одного вида — смерть, не выпить таблеток — смерть, выпить за раз меньше нормы — смерть. Таблетки надо принять за два приема: утром — 2 таблетки (по...