D
D
dmitry-toster2020-03-09 20:29:55
Algorithms
dmitry-toster, 2020-03-09 20:29:55

How to solve this kind of logic problem?

Since childhood, I hate children's riddles and logic questions, the answers to which can be countless, limited only by my own imagination.
Nevertheless, it is necessary to somehow solve ...

Task:

There are 2 trains in the depot. They can be controlled by commands Right, Left and Speed ​​+ all available mats. operators.
These trains were followed by 2 helicopters. They hooked them up and dropped them onto the rails randomly. The distance between trains is unknown.
Task: write code so that the trains meet regardless of how they were dropped by helicopters.
Addition: there are only one rails and they are straight, i.e. trains cannot go in a circle, only back and forth.

Original text in English

There are 2 trains in the factory. You can program them with the following commands: Right, Left and Speed. Plus all the available math commands and programming language operators. 2 helicopters are coming to pick up those trains to throw them to the rails. They drop the trains randomly to the rails. The distance is finite. Your goal is to program the trains so they meet regardless of how the helicopters drop them.

As I think...
In what direction and at what speed the first train will go, and what the second - is unknown.
Therefore, in order to increase the likelihood of their collision, it would be logical for one train to stand still and not go anywhere.
There remains the second train, which must go either to the left or to the right.
If I think correctly, then the first question is: how, in fact, to find out in which direction he should go?
And second: what does speed have to do with it?

I will write the code in JS, but first I need to solve it in human language...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2020-03-09
@dmitry-toster

Let one stand, and the second back and forth with increasing amplitude

spoiler
Похожая задача на англ.: Two robot with parachute in a line

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question