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
a train covers the distance D between two cities in hours arriving 2 hours late.what rate would permit to train to arrive on schedule?
f(X)= 2X-1 + f(X-1) if X is not equal to zeroandiff(X=0)=0, If f(X)-f(X-1)=f(X-8) for X>5 then X= ?
In which of the system, decimal number 194 is equal to 1234?
If a man buys 1 lt of milk for Rs.12 and mixes it with 20% water and sells it for Rs.15, then what is the percentage of gain?
No. of animals is 11 more than the no. of birds. If the no. of birds were the no. of animals and no. of animals were the no. of birds( ie., interchanging no.s of animals and birds.), the total no. of legs get reduced by one fifth (1/5). How many no. of birds and animals were there?
if for h hours of work the salary is s and the employee gets x hours of medical leave, then what is the salary/hr ?
A person has his own coach&whenever he goes to railway station he takes his coach.One day he was supposed to reach the railway station at 5 O'clock.But he finished his work early and reached at 3 O'clock. Then he rung up his residence and asked to send the coach immediately. He came to know that the coach has left just now to the railway station. He thought that the coach has left just now to the railway station.He thought that he should not waste his time and started moving towards his residence at the speed of 3mi/hr.On the way,he gets the coach and reaches home at 6 o'clock.How far is his residence from railway station.
A person went to shop and asked for change for 1.15 paise. But he said that he could not only give change for one rupee but also for 50p, 25p, 10p and 5p. What were the coins he had ?
A tiffin box manufacturer reduces the price of his school kids' tiffin from Rs.30/- to Rs.28/- per tiffin and the price of regular tiffin from Rs.24/- to Rs.23/- per tiffin. A caterer normally spends Rs.1440/- a month for tiffin and 3/4 of this is for regular tiffin. How much will they save a month under the new prices?
hai friends i have finished my B.E CSE in 2009.now i have to get a interview opportunity from HP software ,chennai.please any one can send me the last year(2009) interview questions with answers for freshers.i want a full details about HP's interview question with answers,procedures also.such these one year i had try to get my job but still i have not get.so plese send me that what i said....by vijay,chennai
A cylinder is 6 cms in diameter and 6 cms in height. If spheres of the same size are made from the material obtained, what is the diameter of each sphere?
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
if x/y =4 and y is not '0' what % of 'x' is '2x-y'
If Dev walks 30 miles/hr. he reaches 1 hour before and if he walks with a speed of 20 miles/hr. he reach 1 hour late. Find the distance between 2 points and the exact time of reaching destination is 11 am then find the speed with which he walks.
What is the distance travelled by a ball that falls from a height of 8 mts and each time it bounces half the distance back?