Robots on a line puzle


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.


Add Comment

  • 1 Answer(s)
    Best answer


    [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.
    Add Comment
  • Your Answer

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