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


Please Help Members By Posting Answers For Below Questions

Choose the odd man out from the below mentioned options?

679


What is the 12th term of the series 2, 5, 8, ....

816


Now i am doing RHCE (Red Hat Certified Engineer). Please give some interview questions of linux.

2741


cpahlet : shoulder :: ring : ?

723


Y catches 5 times more fishes than X. If total number of fishes caught by X and Y is 48, then number of fishes caught by X?

802






Area of triangle=(1/2)*b*h base increased by 4 times & height is divided by 2, the net effect of area?

860


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?

2555


1/3 of girls , 1/2 of boys go to canteen. What factor and total number of classmates go to canteen.

1097


Which of the following fractions is less than 1/3

693


B is 20 miles east of A. D is 30 miles east of C. E is 10 miles north of D. C is 20 miles north of B. How far E is from A?

846


A bike runs at the speed of 50 km/h when not serviced and runs at 60 km/h when serviced. After servicing the bike covers a certain distance in 6 h. How much time will the car take to cover the same direction?

786


Find the next number in the series. 1, 0.5, 0.25, 0.125

953


Sum of money at compound interest amounts of thrice itself in 3 years. In how many years will it take 9 times itself.

717


A person meets a train at a railway station coming daily at a particular time . One day he is late by 25 minutes, and he meets the train 5 k.m. before the station. If his speed is 12 kmph, what is the speed of the train.

1035


In a storage stall of 5x3x2inch.How many blanks of size 2x1x1inch can be stored..

1481