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
A 4" cube is painted in all its faces and then it is cut down into 1" blocks. How many 1" blocks are there even without a single face being painted?
In a show, ticket numbers from 101 to 350 are made to sit consecutively. What is the probability that the number of the ticket, selected at random, will be a hundredth digit of 2?
What is the angle between the two hands of a clock when time is 8:30
Two trains move in the same direction at 50 kmph and 32 kmph respectively. A man in the slower train observes the 15 seconds elapse before the faster train completely passes by him. What is the length of faster train?
If g (0)=g (1)=1 And: g (n)= g (n-1) + g (n –2) find g (6);
a man buy a liquid by 12 lts and the mixture is of 20% liquid in water then he makes it in 30% mixture then what is the % of liquid with water.
which country is following one party system
Find the next letter in the series O,T,T,F,F,S,S--
In a two-dimensional array, X (9, 7), with each element occupying 4 bytes of memory, with the address of the first element X (1, 1) is 3000, find the address of X (8, 5).
Find out the Simple Interest paid for a sum of $4000 at the rate of 8% per annum for 3 months.
Sum of a series of n numbers is n+8. Find second (or second last) no.
Using the digits 1,5,2,8 four digit numbers are formed and the sum of all possible such numbers.
Which of the following is not a valid DEFINE GDG parameter a) OWNER b)LIMIT c) SCRATCH c)ALTER
If x,y,z are chosen frm -3,1/2,2 what is the largest value of (x/y)*z*z
Cost of an item is Rs 12.60 ,profit is 10% over selling price.