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 / rajasekar b

D answer sanket may be wrong. U gotta program both the chips.
and u cant say "MB(T1)" to train T2 and viceversa, neither
"IF(T1 at P1)". There is no way for the trains to know where
they are.
My answer is:
MF;
i=1;
do
{
for(j=1;j<=(i*2)+1;j++)
MB;
for(j=1;j<=(i*2)+2;j++)
MF;
}While(1);

This causes both the trains to oscillate about their
respective parachutes,moving a unit length longer in forward
and backward direction for each oscillation. sure, they
gotta BUMP into each other.

My assumption:
Usual programming language constructs can be used.
Given Commands are just for controlling the train.

Is This Answer Correct ?    4 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

In a classroom, a student is ranked 12th from right and 9th from left. How many students are there in total?

698


Fill the empty slots. Three FOOTBALL teams are there. Given below the list of maches. played won lost draw Goals for Goals against A 2 2 *0 *0 *7 1 B 2 *0 *1 1 2 4 C 2 *0 *1 *1 3 7 the slots with stars are answers.

762


in the year 1990 there are 5000 men 3000 women 2000 boys .in 1994 men are increased by 20% women are increased by ratio of boys and women

784


In a family Reshma is elder sister of Ragini . Soni is Reshma's daughter and Saloni is Soni's cousin. Rgini's mother is Rajani. Ramani is the sister-inlaw of Reshma. Who is Soni's grandmother?

937


6 Face of a cube are painted in a manner ,no 2 adjacent face have same colour three colurs used are red blue green. Cube is cut in to 36 smaller cube in such a manner that 32 cubes are of one size and rest of them bigger size and each bigger side have no red side.

743






There is a work which can be completed by A with 12 days and B by 18 days. A and B works together for 3 days and B left. After that how many days for A to complete the work?

671


f(X)= 2X-1 + f(X-1) if X is not equal to zeroandiff(X=0)=0, Value of f(5)

791


Scientific publishing aptitude interview question

989


why we will appoint you.

1790


If all the natural numbers from 256 to 400 are written side by side to each other, a large natural number is obtained. How many times 6 appears in this large natural number?

693


hi had any body attended bank of interview plz........ share your experience

1715


Dear Sir/ Madam, Kindly send me the model question answers for RRB-Technician Signal(Physics/Maths) to saranya67veena@gmail.com

2035


In Madras, temperature at noon varies according to -t^2/2 + 8t + 3, where t is elapsed time. Find how much temperature more or less in 4pm to 9pm.

918


In a colony there are some families. Each of them have children but different in numbers.Following are conditions ano of adult>no of sons>no of daughters>no of families. b>each sister must have atleast one brother and should have at the most 1 sister. no of children in one family exceeds the sum of no of children in the rest families. Tell the no of families.

777


The diameter of a wheel is 1.26m. If this wheel rotates 500 rotations, how long it can travel?

919