📜 ⬆️ ⬇️

Old task about robots

Surely many people know the problem about 2 robots.


I recall the condition:

There are 2 robots.
They are dropped on parachutes to a discrete, infinite line.
Initially, it is unclear what is the distance between robots and who is to the left, and who is to the right.
')
We need to write a program for robots, which will guarantee their meeting.
The program is the same for both robots, there is no communication between the robots.

Valid Operators:
moveLeft // 1 step left
moveRight // 1 step right
goto // go to the n-th line of the program
if (startPoint) goto // check if there is a parachute under your feet. (no matter whose reaction to both your own and someone else's) if true, go to the n-th line of the program.

All my life I thought that there is only one solution (until I say it, maybe someone sees the task for the 1st time).
But recently I was told that my decision was wrong 0_o, motivating it with the fact that
Each operation is performed instantly, so my solution does not go down.

Can someone here suggest a solution that feeds under the additional limitation of "instant command execution"?
I just somehow seem too stupid for this ...

upd : if robots are in the same cell, then everything is a victory. The extra if only clutters up (in this case) the code, the salt in the algorithm.

upd2:
The right decision (the idea is just to catch up with him):
1: right
2: if (startPoint) goto 4
3: goto 1
4: right
5: right
6: goto 4

upd3: in short, it's all a hat. The comrade who invented the condition about “instantaneousness” came up with some strange “solution”:
1. if (startPoint) goto 6
2. right
3. right
4. left
5. goto 2
6. right
7. goto 6
After all, it is not alone that it seems absurd to me, not even a solution?

upd4: he probably meant
0. right
but it does not change anything in the context of the "instantaneous" performance.

Source: https://habr.com/ru/post/84494/


All Articles