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
Area of triangle=(1/2)*b*h base increased by 4 times & height is divided by 2, the net effect of area?
There are 12 boys and 15 girls, How many different dancing groups can be formed with 2 boys and 3 girls. Which of the following fractions is less than 1/3?
Hi friends i am new to this site. Pls provide me the KVB clerical exam model question papers. pls send to mail id mailstoaaa@gmail.com. Hope u guys will help me.
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.
There are 150 weights .Some are 1 kg weights and some are 2 kg weights. The sum of the weights is 260.What is the number of 1kg weights?
Find the value of (1.99)2
In how many rows will 200 Miranda bottles be placed, if 200 Miranda bottles are stacked in such a way that there are 20 bottles in the bottom, 19 in the next row, 18 in the row next and so on?
what is the number whose reminder is 2 after dividing 5and also reminder is 4 after deviding 7 and reminder is 6 after deviding 9?
---- of a mutual instrument vibrate 6,8 & 12 intervals respectively. If all three vibrate together what is the time interval before all vibrate together again?
Three independent mechanisms A, B and C have been incorporated for power saving in a plant producing respectively 30%, 40% and 10% efficiency. Assuming that they operate independently, what is the net power efficiency achieved
How many ways can one arrange the word EDUCATION such that relative positions of vowels and consonants remains same?
The time showed by the clock at a moment is 8 am then the respective time of after and before 42896 hours is :
Now i am doing RHCE (Red Hat Certified Engineer). Please give some interview questions of linux.
Average of 5 number is -10 sum of 3 numbers is 16,what is the average of other two numbers?
How is the father of the man ,who is the brother of the only aunt of my brother related to me?