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 / rshadow

Rajasekar's answer is almost correct, but:

1. i has to be increased by 1 at each iteration of the while
loop.

2. since the 2 trains are facing the same direction at the
start, using this solution will not work - the 2 trains will
always go at the same direction and will never bump into
each other. To overcome this pitfall we need to use a
statement such as 'if (P) STOP', (or: if (P) GOTO END).

notice that above I assume that the condition if (P) is only
satisfied when the train is next to the OTHER train's
parachute. Otherwise, using a counter we can check if the
train is next to its own parachute or not.

Is This Answer Correct ?    5 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Hansie made the following amounts in seven games of cricket in India: Rs.10, Rs.15, Rs.21, Rs.12, Rs.18, Rs.19 and Rs.17(all figures in crores of course).Find his average earnings.

899


There are 3 societies A,B,C having some tractors each. A Gives B and C as many tractors as they already have. After some days B gives A and C as many tractors as they have. After some days C gives A and B as many tractors as they have. Finally each has 24 tractors.what is the original No.of tractors each had in the beginning?

987


A car is filled with four and half gallons of oil for full round trip. Fuel is taken 1/4 gallons mor3 in going than coming. What is the fuel consumed in coming up?

1069


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

1753


There was a ques on work something like 2 typists type 2 papers in 4 hrs then in how much time will 5 typists take or something like that.

1200






A company manufactures x refrigerators cp.(9000+500x0 sp=500x; what must be the value of x so that atlas the amount gained After selling is equal to the amount spent on production

813


What is the distance travelled by a ball that falls from a height of 8 mts and each time it bounces half the distance back?

705


Conversation between two mathematicians: first : I have three children. The product of their ages is 36 .. If you sum their ages . it is exactly same as my neighbour's door number on my left. The second mathematician verifies the door number and says that the not sufficient . Then the first says " o.k one more clue is that my youngest is the youngest" Immediately the second mathematician answers . Can you answer the question asked by the first mathematician? What are the children ages?

1672


ABCE is an isosceles trapezoid and ACDE is a rectangle. AB = 10 and EC = 20. What is the length of AE?

1544


what types of question tricom will ask

1644


With a 4/5 full tank a vehicle can travel 12 miles, how far can it travel with a 1/3 full tank

1278


If x and x+10 are lengths containing right angle, what is the equation if area is 24 sq.cm

670


What is the max possible 3 digit prime number?

783


Solve for x and y: 1/x - 1/y = 1/3, 1/x2 + 1/y2 = 5/9.

1129


Three men A, B, C can complete a work separately in some specified days (May be 8, 7, 6).If they do the work together by alternate days. Then how many days need to complete the work?

863