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 batsman scores 23 runs and increases his average from 15 to 16. Find the runs to be made if he wants top Inc the average to 18 in the same match.
The area of the maximum size of the circle described from the 10 square inch square?
The house is big and lovely but since nobody uses it it is pretty much a white Elephant What does White Elephant mean?
A small town's industries have a total turnover of Rs. 25,00,000. If the town council plans to raise Rs.170,000 through octroi levy, what % levy should it charge on the industries?
a father is 30 times more than his son however he will be only thrice as old as the son what is father's present age ?
Sita bought a handbag for Rs. 144 and got a percentage of profit equal to the cost price of the handbag. What is the cost price of the handbag?
hi had any body attended bank of interview plz........ share your experience
there is a safe with a 5 digit No. The 4th digit is 4 greater than second digit, while 3rd digit is 3 less than 2nd digit. The 1st digit is thrice the last digit. There are 3 pairs whose sum is 11. Find the number.
Two persons start at the same point, walk in opposite directions with 5km/hr and 5.5km/hr respectively. What is the distance separated after 2 and half hrs?
How many digits will be there to the right of the decimal point in the product of 95.75 and .02554 ?
There are 200 employees in a company. An external vendor is chosen to Serve coffee twice a day. 100 coffee cups were offered by the company but as an incentive to have the cups in tact at the end of the day, the company offered 30 paise for every cup remained safely and charged 90 paise for every broken cup. At an end of a day, the vendor received Rs. 24. How many cups did the vendor break? 10, 20, 8, 5?
1/3 of girls and 1/2 of boys is goto canteen. What factor & total no. of class mates goto canteen.
The average of the first 100 positive integers is?
12 men can build wall of length of 12m in 10 days how many men are required to build 20 m in 15 days.
Sir iam going to write exam for the post of Officers under training in APSRTC. Please send me the model papers to my mail ganjiramji@gmail.com