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


Please Help Members By Posting Answers For Below Questions

sir, ihave cleared my ssc so(acctts) written exam i want to some tips for interveiw

1739


1,2,3,4,5,6,7,8,9 station. route between any 2 station is there only if the 2 digit nob. is divisible by 3. e.g. route exist between 1 to 2 because 12 is divisible by 3 how many station have routes to 8 either direct or indirect

739


Some work is done by two people in 24 minutes. One of them can do this work alone in 40 minutes. How much time does the second person take to do the same work ?

704


a block of ice floats on water in a beaker, as the ice melts,the water level in the beaker will

665


Asian paints takes a contracts to paint 3 houses. Mr. White can paint a house in 6 days while Mr.Blue would take 8 days and Mr.Red 12 days. After 8 days Mr.White goes on a holiday and Mr. Blue begins to work for a period of 6 days. How many days will it take Mr.Red to complete the work?

711






There are 12 boys and 15 girls, How many different dancing groups can be formed with 2 boys and 3 girls. Which of the following fractions is less than 1/3?

981


what is the exact qualifing marks for group 1 prelims

1833


what is the syllabus for group-1 and upsc exam for ias also specify the age limit for both appsc and upsc exams. is there any age relaxation for divorced women.

3043


Robert invested rupees 8000 in a fixed deposit scheme for 2 years at compound interest of 5 p.c per annum. Calculate and choose from the below mentioned option, how much amount will Robert get from the fixed deposit on maturity?

733


If the operation,^ is defined by the equation x ^ y = 2x + y,what is the value of a in 2 ^ a = a ^ 3

777


There are 9 balls of equal size and same weight (they look similar) except 1. How may weighs required to find the dissimilar ball using a weighing balance?

717


There are 200 employees in a company. An external vendor is chosen to Serve coffee twice a day. 100 coffee cups were offered by the company but as an incentive to have the cups in tact at the end of the day, the company offered 30 paise for every cup remained safely and charged 90 paise for every broken cup. At an end of a day, the vendor received Rs. 24. How many cups did the vendor break? 10, 20, 8, 5?

1636


A ship is away from the shore by 180 miles.A plane is travelling at 10 times speed of the ship.How long from the shore will they meet?

1000


If the product of three consecutive int is 210,then sum of the two smaller ints is:

714


X2 – (A-3)X +(A+3) = 0 for what value of A the sum of square of roots will be least ?

780