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 mother is 30 years older than her daughter however she will be only thrice as old as the daughter after 5 years. What is mother’s present age ?
Find the next number in the series 0,3,8,15,,24,48,63--
if f(x)=1/x**2 , then f(f(f(x)))
A train blows a siren one hour after starting from the station. After that it travels at 3/5th of its speed it reaches the next station 2 hours behind schedule. If it had a problem 50 miles farther from the previous case,it would have reached 40 minutes sooner. Find the distance between the two stations .
. Select the correct statement a. NEXT SENTENCE and CONTINUE functionally does the same. b. Never can code a DECLARE CURSOR statement in procedure division. c. Edited numeric characters can be included in arithmetic operations. d. The Sub parameters of a DCB parameter are Keyword parameters.
Ajay can build a house in 16 days and Barry can do the same job in 12 days. With help of Chintu, they did the job in 4 days only. How many days Chintu can do the job?
three students appear in a test but no one write there name on answer sheet .and they submitted their sheet to teacher . when teacher distributed their answer sheet . what is probability that no one get their own answer sheet.
There are two trees in a lawn. One grows at a rate 3/5 of the other in 4 years. If the total growth of trees What is the height of the smaller tree after 2 years
Dinesh is seated 7 from the left and satish is seated 12 from the right. when they interchange their positions, dinesh is seated 22nd from the left. How many people are there?
Length and breadth of a rectangle are in ratio 7:5. If length is reduced by 5 and breadth by 2, area reduces by 65. Find length and breadth.
Find the next series: AA AB BC CE ?
I want the sbi clerical exam model papers
How many 3-digit numbers will be there which are divisible by 19?
‘a‘ number of persons work daily ‘b’ hours to produce ‘c’ items. If ‘d’ persons walks away from the group what will be the number of hours to produce ‘c’ items. ?
There are 40 seats in a bus. People agree to share the money for the number of seats. The total money comes to 70.37. How many seats were free?