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 / vinayak
MF
IF (P)
GOTO B
GOTO A
-----
B: MF
GOTO B
Explanation: The first line simply gets them off the
parachutes. You
need to get the trains off their parachutes so the back
train can find
the front train's parachute, creating a special condition
that will
allow
it to break out of the code they both have to follow
initially. They
both loop through A: until the back train finds the front
train's
parachute, at which point it goes to B: and gets stuck in
that loop.
The front
train still hasn't found a parachute, so it keeps in the A loop.
Because each line of code takes a "clock cycle" to execute,
it takes
longer
to execute the A loop than the B loop, therefore the back train
(running
in the B loop) will catch up to the front train.
| Is This Answer Correct ? | 12 Yes | 2 No |
Post New Answer View All Answers
A store was earning 25% profit after giving a discount of almost 25%,. If they now give 10% discount then what is the profit percentage earned.
There are 150 weights .Some are 1 kg weights and some are 2 kg weights. The sum of the weights is 260.What is the number of 1kg weights?
A gardener plants 100 meters towards east, next 100 meters towards north,next 100 meters towards west. 98 meters towards east, 96 meters towards north and 96 meters towards west, 94 meters towards south. and 94 meters towards east and so on. If a person walks between the trees what is the total distance travelled by him before he reaches the center.
What is the angle between the two hands of a clock when time is 8:30
need Thomson Reuters Questions and Answers
A & B are playing a game .There are 8 oranges in a row on the table.one Player can take 1-4 oranges in a pick (a maximum of 4),one who picks the last orange wins the game.'A' plays first How many oranges should he pick first time inorder to win the game.
There is a lucky draw held every day. If there is a winning number eg. 1876, then all possible numbers like 1867 ,1687,1768 etc are the numbers that match irrespective of the position of the digits. Thus all these numbers qualify fr the lucky draw prize. Assume there is no zero digit in any numbers. Write a program to show all the possible winning numbers if a "winningnumber" is passed as an argument to the function. i want a solution in c/c++ language
if a man byes 1 lt of milk for 12 rs and mixes with 20% of water and sels it for rs 15 thgen what is percentage of gain
If INDIA = JOEJB then BSNZ =?
if the radius of the circle is increased by 6% then its area increased by
What is the maximum number of half-pint bottles of cream that can be filled with a 4-gallon can of cream(2 pt.=1 qt. and 4 qt.=1 gal)
If 8 men are required to complete a work in 6 days, how many men will be required to complete the same work in ½ day?
xsqrt(0.09)=3 , then x equals
In which of the system, decimal number 194 is equal to 1234?
If A=Z, B=Y, C=X, .......... Z=A, Then GROUP = ?