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
In the word ECONOMETRICS, if the first and second , third and forth ,forth and fifth, fifth and sixth words are interchanged up to the last letter, what would be the tenth letter from right?
if a=2, b=3, c=6 Find the value of c/(a+b)-(a+b)/c
Sunny ate 100 apples in five days, each day eating 6 more than the previous day. How many apples did he eat on the first day?
hai friends i have finished my B.E CSE in 2009.now i have to get a interview opportunity from HP software ,chennai.please any one can send me the last year(2009) interview questions with answers for freshers.i want a full details about HP's interview question with answers,procedures also.such these one year i had try to get my job but still i have not get.so plese send me that what i said....by vijay,chennai
The equivalent compound ratio of 5:6::7:10::6:5
The Parallelogram PQRS, the line RS have midpoint T from line PQ. What is the ratio of Triangle PTS / parallelogram PQRS?
9/10 or 10/11 which is greater.
what is diff b//w the singly reinforced beam,doubly reinforced beam?
cpahlet : shoulder :: ring : ?
"what category of job are you looking for and why"asked from an mep engineer.
What kind of questions are there in Harbinger Aptitutde test paper(for 2011)and their paper pattern?Plz reply urgently.
a bus started from bus stand at 8.00am and after 30min staying at destination it returned back to the buss tand.the destination is 27 miles from the bustand the speed of the bus 50percent fast speed at what time it returns to the bustand.
Ms. Anurag Awasthi deposits an amount of Rs. 56500 to obtain a simple interest at the rats of 12% p.a. for 3 years. What total amount will Mr. Anurag Awasthi get at the end of 3 year?
Joe started from Bombay towards pune and her friend julie in opposite direction.they meet at a point .distance travelled by joe was 1.8 miles more than that of julie.after spending some both started there way.joe reaches in 2 hours while julie in 3.5 hours. Assuming both were travelling with constant speed.Wath is the distance between the two cities.
a train covers the distance D between two cities in hours arriving 2 hours late.what rate would permit to train to arrive on schedule?