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

how to retrieve the recent record from the database using sql query. suppose the table has the columns only ename,job,salary columns

1745


which questions are asked in pnb related tocomputer and marketing apptitude

3570


A cylinder is 6 cms in diameter and 6 cms in height. If spheres of the same size are made from the material obtained, what is the diameter of each sphere?

823


The sum of the series 1 + 1(1+1/n) + 3(1+1/n)2 + ..... is equal to?

740


What is the probability of getting a sum 9 from two throws of a dice?

899






THERE ARE 3 PILES OF BOOKS ON THE TABLE YOU NEED TO ARRANGE THEM IN THE SELF SUCH THAT 1ST BOOK OF EACH PILE GETS PLACED ON THE SELF,WHAT IS THE POSSIBLE NO OF ARRANGEMENTS

3099


two persons run a race of 100m. the winner won by (110/11)m and one second in time. find the speed of lsoer in met

720


sir i need rrb secunderabad goods guard previous exam model papers

1980


500 men are arranged in an array of 10 rows and 50 columns . ALL tallest among each row aare asked to fall out . And the shortest among THEM is A. Similarly after resuming that to their originaal podsitions that the shorteest among each column are asked to fall out. And the longest among them is B . Now who is taller among A and B ?

696


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

851


If a square is formed by the diagonal of the square as an edge, what is the ratio between the area?

1026


WRITE A LEAVE LETTER TO YOUR MANAGER

1818


which country is following one party system

1962


Hello My name is vijay right now I'm preparing for SBI po, I am good at aptitude but not better. I am lagging time you know competitive exams are to answer in span of time. So any website regarding aptitude short cuts or tricks Pls post to my mail. I am waiting

1585


Aeroplane is flying at a particular angle and latitude,after some time another latitude is given..(8 hrs later), You are asked to find the local time of the place.

663