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

In geometry, polygons with up to twelve sides have different given names; however, ______________________ if the number of sides is higher than twelve, the polygon is named by placing the suffix "gon" after the number of sides in the polygons. if the number of sides is greater than twelve, the polygon is named by placing the suffix "gon" after the number of sides in the polygons. if the number of sides is greater than twelve, name the polygon by placing the suffix "gon" after the number of sides in the polygons. if the number of sides is higher than twelve, name the polygon by placing the suffix "gon" after the number of sides in the polygons.

1661


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

1463


A plane moves from 9? N40? E to 9? N40? W. If the plane starts at 10 am and takes 8 hours to reach the destination, find the local arrival time.

913


There are 4 boys and 3 girls. What is the probability the boys and girls sit alternately?

756


Alok and Bhanu play the following min-max game. Given the expression N = X - Y – Z where X, Y and Z are variables representing single digits (0 to 9), Alok would like to maximize N while Bhanu would like to minimize it. Towards this end, Alok chooses a single digit number and Bhanu substitutes this for a variable of her choice (X, Y or Z). Alok then chooses the next value and Bhanu, the variable to substitute the value. Finally Alok proposes the value for the remaining variable. Assuming both play to their optimal strategies, the value of N at the end of the game would be • 4 • -18 • 9 • 2

2149






There are three trucks A, B, C. A loads 10 kg/min. B loads 13 1/3 kg/min. C unloads 5 kg/min. If three simultaneously works then what is the time taken to load 2.4 tones?

882


The ratio of the length : breadth : height of a cuboid is 5 : 4: 3, and the volume is 7500. What will be its surface area ?

823


If shalu buys 6 more apples, his carton will weigh 14.5 kilograms.if the weight of one apple is 250 grams.how many apples did he initially had in his carton?

1088


A father F has 5 sons, p,q,r,s,t. Not necessarily in this order. Two are of same age. The eldest and youngest cannot be twins. T is elder to r and younger to q and s has three older brothers. who is the oldest and youngest?

749


A thief steals half the total no of loaves of bread plus 1/2 loaf from a bakery. A second thief steals half the reaming no of loaves plus 1/2 loaf and so on. After the 5th thief has stolen there are no more loaves left in the bakery. What was the total no of loaves did the bakery have at the beginning.

892


One man brought pen and book from 250 and he sold both at 10% profit on pen and 20% loss on book and finally he gained 40% what is the value of pen

761


Instead of multiplying a number by 7, the number is divided by 7. What is the percentage of error obtained?

915


What is the total distance covered by Sachin if he covers 2/3 rd of the distance at 4 kmph and the remaining distance at 5 kmph in 1hr 24min?

688


Find the next series of 1,2,2,4,8,?

798


If a clock takes 7seconds to strike 7, how long will the same clock take to strike 10?

805