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 / rshadow
Rajasekar's answer is almost correct, but:
1. i has to be increased by 1 at each iteration of the while
loop.
2. since the 2 trains are facing the same direction at the
start, using this solution will not work - the 2 trains will
always go at the same direction and will never bump into
each other. To overcome this pitfall we need to use a
statement such as 'if (P) STOP', (or: if (P) GOTO END).
notice that above I assume that the condition if (P) is only
satisfied when the train is next to the OTHER train's
parachute. Otherwise, using a counter we can check if the
train is next to its own parachute or not.
| Is This Answer Correct ? | 5 Yes | 6 No |
Post New Answer View All Answers
Find the product of the prime numbers between 1-20
a train runs first half of the distance at 40 km/hr and the remaining half at 60 km/hr. What is the average speed for the entire journey?
What would be the rank of the word LABOUR in the dictionary if all the possible permutations of the alphabets of LABOUR are done?
L:says all of my other 4 friends have money M:says that P said that exact one has money N:says that L said that precisely two have money O:says that M said that 3 of others have money. P:Land N said that they have money. all are liers.Who has money&who doesn't have?
In a fraction, if 1 is added to both the numerator at the denominator, the fraction becomes 1/2. If numerator subtracted from the denominator, the fraction becomes 3/4. Find the fraction.
The Parallelogram PQRS, the line RS have midpoint T from line PQ. What is the ratio of Triangle PTS / parallelogram PQRS?
A work is done by two people in 24 minutes. One of them alone can do it in 40 minutes. How much time will the other person will take to complete it
x:y=3 and x+y=80 what is the value of y?
A train overtakes two persons walking along a railway track. The first one walks at 4.5 km.hr . the other one walks at 5.4 km/hr. the train needs 8.4 and 8.5 seconds respectively to overtake them, What is the speed of the train if both the persons are walking in the same direction as the train?
Find the correct meaning of the following phrase: Man of few words
There are 6 people W,H,M,C,G,F who are murderer, victim, judge, police, witness, hangman. There was no eyewitness only circumstantial witness. The murderer was sentenced to death. Read following statement and determine who is who.
Jane works at a fashion design company,and is having problems getting dressed for work. She refuses to wear any color combination that does not go well together as many of her clients may look down upon this. She has two pairs of skirts, brown and blue; three blouses, white, sky blue, and gray; four pairs of stockings, red, black, brown, and blue; and two pairs of shoes, black and brown. The blue skirt cannot be worn with red or brown stockings. Gray does not go well with brown. Black does not go well with brown. 1. If Jane wears black shoes she will not wear: a) red stockings. b) a blue skirt. c) a white blouse. d) blue stockings. e) a sky blue blouse. 2. If Jane is color blind and is unable to determine what outfits went well together, how many possible clothing combinations could she have? a)24 b)32 c)36 d)44 e)48 3. If Jane wears a brown skirt and a white blouse, she could: a)not wear blue stockings. b)not wear brown shoes. c)not wear black shoes. d)wear blue stockings. e)wear red stockings. 4.Jane buys a gray scarf. If she wears the new scarf, then she could: a)not wear blue stockings. b)not wear brown stockings. c)not wear black shoes. d)wear a white blouse. e)wear black stockings. 5.Jane will never wear: a)blue and red together. b)white and red together. c)gray and blue together. d)white and black together. e)white and red together.
The house is big and lovely but since nobody uses it it is pretty much a white Elephant What does White Elephant mean?
if 2 miles of fence enclose a square plot of 160 acres,how large a square will 4 miles of fence
Why RSD of area limit is 15?