# Robots on a line puzle

732.8K Views

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.

SherlockHolmes Expert Asked on 1st July 2017 in

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.

• ## More puzzles to try-

• ### Commute to School

Mrs. Benette was a school teacher who noticed that she took the same time to go to school in the ...Read More »
• ### Car with missing wheel riddle

You Are in A Car, of which one wheel is missing. But Suddenly, There is a killer coming from your ...Read More »
• ### What does 1111/TIME mean

What does 1111/TIME meanRead More »
• ### Everything is here riddle

Everything is here, one score and nine, that shelter a vast mob. It lets lions lie down with the lambs, ...Read More »
• ### You always overlook

No matter how smart you are, there is one thing you will always overlook. What is it?Read More »
• ### It is flat

It is flat. You use it everyday. You need it to live. But you give it away everyday. It is ...Read More »
• ### implement isPalindrome(int n)

Implement the function boolean isPalindrome (int n); Which will return true if the bit-wise representation of the integer is a ...Read More »
• ### If 7×7 = 12 puzzle

If 7×7 = 12 5×5 = 8 3×3 = 4 2×2 = 2 Then 6×6 = ?Read More »
• ### Shortest complete sentence

I am the shortest complete sentence in the English language. What am I?Read More »
• ### Will the ant ever reach the other end of the rope?

An ant gets onto one end of a tight rope that is 1 meter long. The ant is traveling at ...Read More »
• ### Born in 18th century

It was born in the 18th century, yet still live on today. Appearing on TV when he has something to ...Read More »
• ### Trick Gift Brain Teaser

Cindy opened twenty five presents. Duke opened five presents. John opened fifteen presents. Judging by the statements, can you decipher ...Read More »
• ### Bright and yellow

It is bright and yellow and turn on and off everyday, some say they need me but others wish that ...Read More »
• ### Help Arun to come out of maze puzzle

Arun got stuck in a maze with a many-headed Minotaur ready to kill him any instant. He has only one ...Read More »
• ### Man and his boss have the same parents riddle

A man and his boss have the same parents, but are not siblings. How is this possible?Read More »
• ### Make Six Square

In the given figure, you can see that four match sticks are used to form a square. Can you form ...Read More »
• ### Complete the pairs

Write the missing half of each word pair ? 1. Peace and 2. Thunder and 3. Back and 4. Thick ...Read More »
• ### Found underground riddle

These are a type of starchy food Mashed or fried they can be found They often come from Idaho And ...Read More »
• ### Choose the Door of Freedom

You are a prisoner in a room with 2 doors and 2 guards. One of the doors will guide you ...Read More »
• ### How many do you have to draw to be sure that you have a pair?

There are 32 red socks and 32 blue socks in the drawer. You can’t tell which sock is right and ...Read More »