Robots on a line puzle

1,126.4K Views
Answered

Two robots are placed at different points on a straight line of infinite length. When they are first placed down, they each spray out some oil to mark their starting points.

You must program each robot to ensure that the robots will eventually crash into each other. A program can consist of the following four instructions:

  • Go left one space
  • Go right one space
  • Skip the next instruction if there is oil in my current spot
  • Go to a label

[Note that a “label” is a name that refers to a line of your code. For example, you could label the third line of your program “surveying”. Then, the instruction “goto surveying” would jump to line 3 and start executing from there on the next cycle.]

A robot will carry out one instruction per second. Both robots need not have the same program. Note that you won’t know ahead of time which robot is on the left and which is on the right.

 

Share
Add Comment

  • 1 Answer(s)
    Best answer

    Algorithm-

    [Label: move_slowly]
    1 Move Right
    2 Move Right
    3 Move Left
    4 Skip Next Instruction If On Oil
    5 GOTO move_slowly

    [Label: move_quickly]
    6 Move Right
    7 GOTO move_quickly

    SherlockHolmes Expert Answered on 5th July 2017.

    The Question is not clear enough: Once the robot turned right one step and  gets another order “go right one step” he does not keep straight but turns right from the last point!! I tried to draw the solution and I found that I got a shape of cross where I go back to where I started so now if the robot is facing the oil he goes to the instruction move right again and again so he move in a circle starting from the oil point. This is also that case of the 2nd robot. So how do they meet?

     


    let the blue line bee the infinite line between north and south and the robot facing north at point A. So by going right, right, left,  then after four times we get back to where we started ,  and now going only right moves us in circle!!

    on 3rd August 2022.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.
  • More puzzles to try-