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 / sanket
Assumptions - the track goes North-South
Both trains either face or North or South
Two trains are T1 and T2 and their respective parachutes
are P1 and P2
Algorithm/code-
MF(T1) //Moves T1 in forward direction
MF(T2) //Moves T2 in forward direction
Label:If(T1 at P2) MB(T2)
If(T2 at P1) MB(T1)
GOTO Label
Description - Since both trains are facing same direction
(either N or S) if both start moving forward (say toward N)
at some point of time one train will cross other train's
parachute, at which point we reverse the other train. The
trains are now on a collision course.
| Is This Answer Correct ? | 4 Yes | 17 No |
Post New Answer View All Answers
A tailor has 37.5 metres of cloth and he has to make 8 piecesout of a metre of cloth. How many pieces can he make out of this cloth?
There are 19 red balls and one black ball . Ten balls are put in one jar and the remaining 10 are put in another jar. what is the possibility that the black is in the right jar.
if for h hours of work the salary is s and the employee gets x hours of medical leave, then what is the salary/hr ?
(998-1)(998-2)(998-3).....(998-n)= ? when n>1000
Zulus always speak truth and Hutus always speak lies. There are three persons A,B&C. A met B and says " I am a Zulu or I am Hutu". We don't know what exactly he said. then B meets C and says to c that " A is a Zulu ". Then C replied " No, A is a Hutu ". Who must be a Zulu ?
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?
Four friends are given named Akansha, Anuska, Anisha, ... , ... Each of them live in a separate home and sleep on one bed. Akansha and Anuska have two extra beds, two of the house have green lawns while the rest have narrow porchs, One of the house has Airconditioner while the rest have fans
If A, B and C are the mechanisms used separately to reduce the wastage of fuel by 30%, 20% and 10%. What will be the fuel economy if they were used combined.
2020201-565656=?
After spending 2/3 of his salary on rent and food items and 1/4th of the remaining on transportation, Rajesh has 6000 with him. How much did he pay on transportation?
Why RSD of area limit is 15?
2 is what % of 4t ?
Q1. Given a collection of points P in the plane, a 1-set is a point in P that can be separated from the rest by a line, .i.e the point lies on one side of the line while the others lie on the other side. The number of 1-sets of P is denoted by n1(P). The minimum value of n1(P) over all configurations P of 5 points in the plane in general position(.i.e no three points in P lie on a line) is
Ajay can build a house in 16 days and Barry can do the same job in 12 days. With help of Chintu, they did the job in 4 days only. How many days Chintu can do the job?
A person was fined for exceeding the speed limit by 10 mph. Another person was also fined for exceeding same speed limit by twice the same. If the second person was travelling at a speed of 35 mph, find the speed