A helicopter drops two trains, each on a parachute, onto a
straight infinite railway line. There is an undefined
distance between the two trains. Each faces the same
direction, and upon landing, the parachute attached to each
train falls to the ground next to the train and detaches.
Each train has a microchip that controls its motion. The
chips are identical. There is no way for the trains to know
where they are. You need to write the code in the chip to
make the trains bump into each other. Each line of code
takes a single clock cycle to execute.
You can use the following commands (and only these);
MF - moves the train forward
MB - moves the train backward
IF (P) - conditional that's satisfied if the train is next
to a parachute. There is no "then" to this IF statement.
GOTO
Answer Posted / vinayak
MF
IF (P)
GOTO B
GOTO A
-----
B: MF
GOTO B
Explanation: The first line simply gets them off the
parachutes. You
need to get the trains off their parachutes so the back
train can find
the front train's parachute, creating a special condition
that will
allow
it to break out of the code they both have to follow
initially. They
both loop through A: until the back train finds the front
train's
parachute, at which point it goes to B: and gets stuck in
that loop.
The front
train still hasn't found a parachute, so it keeps in the A loop.
Because each line of code takes a "clock cycle" to execute,
it takes
longer
to execute the A loop than the B loop, therefore the back train
(running
in the B loop) will catch up to the front train.
| Is This Answer Correct ? | 12 Yes | 2 No |
Post New Answer View All Answers
Find the next series: BC CE EG GK ?
Number of digits with a 2 in them between 100 and 400?
Ram starts from A walking 2 km North and turns right and walks 4 km and turns right again and walks 4 km and turns right again and walks 4 km and meets Radha at Bwalking in the opposite direction to Ram . Distance between A and B
A boy has Rs 3 in total. If he wins, he gains 1 Rupee and if he looses, he has to loose 1 Rupee. The boy may lose only 5 times in the game and if he earns 5 Rs, he has to quit the game. Find the number of ways of the possibilities.
20% of a 6 litre solution and 60% of 4 litre solution are mixed. What percentage of the mixture of solution ?
f(X)= 2X-1 + f(X-1) if X is not equal to zero and if f(X=0)=0, If f(X)=4f(X-1) then the value of X=?
If 4 circles of equal radius are drawn with vertices of a square as the center, the side of the square being 7 cm, find the area of the circles outside the square?
A sum of money becomes 2.5 times itself at 12.5% simple interest p.a. What should be the period of investment to get this much return?
Add a word in starting of SCAPE and at the end of Grass, u will get two different word
The diameter of a circle is 21 metres. It will take how many revolutions to cover a distance of 6.6 km?
Complete the series..2 2 12 12 30 30 ?
sadrine's avg on four tests is 80 which of the following cannot be the number of tests on which she earned exactly 80 points
In a triangle, the average of the two angles is 56 degrees where as their difference is 24 degrees. What is the measurement of the biggest angle of the triangle?
Ram starts from A walking 2 km North and turns right and walks 4 km and turns right again and walks 4 km and turns right again and walks 4 km and meets Radha at Bwalking in the opposite direction to Ram . Which direction does Ram walk after the first turn?
There are 9 balls of these one is defective. Find the minimum no. of chances of finding the defective one.