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 / sanket
Assumptions - the track goes North-South
Both trains either face or North or South
Two trains are T1 and T2 and their respective parachutes
are P1 and P2
Algorithm/code-
MF(T1) //Moves T1 in forward direction
MF(T2) //Moves T2 in forward direction
Label:If(T1 at P2) MB(T2)
If(T2 at P1) MB(T1)
GOTO Label
Description - Since both trains are facing same direction
(either N or S) if both start moving forward (say toward N)
at some point of time one train will cross other train's
parachute, at which point we reverse the other train. The
trains are now on a collision course.
| Is This Answer Correct ? | 4 Yes | 17 No |
Post New Answer View All Answers
Light glows for every 13 seconds . How many times did it glow between 1:57:58 and 3:20:47 am.
The sum of the digits of a two digit number is 8. When 18 is added to the number, the digits are reversed. the number?
Package information is stored in a) DB2 Directory b) DB2 system tables c) DB2 catalog tables d) None of the above
There is a 14 digit credit card number in which every 3 consecutive digits add to 20. Here is a part of it.. Find the value of 'x'? _ _ _ 9 _ _ _ x _ _ _ 7 _ _
There are no of urns &no of balls. If three balls are placed in each urn then 3 balls is left. If 4 balls are placed in each urn then 1 urn is left. What is the total no of balls?
A person has Rs 100/- in his pocket, he can as 25 pencils or 15 books. He kept 15% of the money for travelling expenses and purchased 5 pencils. So how many books he can purchase with the remaining money.
A man is running around a rectangle it takes time 2 time in travelling length than travelling width total perimeter = 300. Find area.
A class consists of 100 students, 25 of them are girls and 75 boys; 20 of them are rich and remaining poor; 40 of them are fair complexioned. The probability of selecting a fair complexioned rich girl is
How would you measure 4 liters using jugs of 3l and 5l? Give a few solutions to this problem?
A can do a work in 8 days, B can do a work in 7 days, C can do a work in 6 days. A works on the first day, B works on the second day and C on the third day rely. that is they work on alternate days. When will they finish the work.(which day will they finish the work) (7+7/168)
GOOD is coded as 164 then BAD coded as 21.if ugly coded as 260 then JUMP?
A 2D array is declared as A[9,7] and each element requires 2 byte.If A[ 1,1 ] is stored in 3000. Find the memory of A[8,5] ?
A father is 30 years older than his son however he will be only thrice as old as the son after 5 years what is father's present age ?
I most like to work with? Most men act though?
new town is straight to the north of new york. A high way m runs from newtown making an angle of 61 degree south east. From new york there is also an high way n which runs northeast 61 degrees. If high ways m and n are straight then find out the acute angle made at their intersection point.