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


Please Help Members By Posting Answers For Below Questions

Total balls z,red balls N remaining are blak balls,then %of black balls equal to

700


there are two categories of persons in ratio a:b = 2:3. A type earns 2.5 dollars/hr and b type 1 dollar/hr total money earned by both is 24dollars. Then what is the total number of persons

697


12 men can build wall of length of 12m in 10 days how many men are required to build 20 m in 15 days.

793


A can do a piece of work in 30 days, which B can do in 20 days. Both started the work but A left 5 days before the completion of the work. It took how many days to complete the work?

727


Conversation between two mathematicians: first : I have three children. The product of their ages is 36 .. If you sum their ages . it is exactly same as my neighbour's door number on my left. The second mathematician verifies the door number and says that the not sufficient . Then the first says " o.k one more clue is that my youngest is the youngest" Immediately the second mathematician answers . Can you answer the question asked by the first mathematician? What are the children ages?

1672






Argentina had football team of 22 player of which captain is from Brazilian team and goalie from European team. For remaining player they have picked 6 from argentine and 14 from European. Now for a team of 11 they must have goalie and captain so out of 9 now they plan to select 3 from Argentinean and 6 from European. Find out no of methods available for it. (2 marks)

798


k, l are men who take home a salary of x, y respectively.the total amount taken home is

693


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?

1432


Can someone please send me the question paper for graduate level both tier 1 and tier 2 with detailed solution of maths exam (Tier 2). Please,suggest me the ways and books to prepare for this exam.Please, send this answer on my email Id

1553


Ram, Shyam and Gumnaam are friends.Ram is a widower and lives alone and his sister takes care of him. Shyam is a bachelor and his niece cooks his food and looks after his house. Gumnaam is married to Gita and lives in large house in the same town. Gita gives the idea that all of them could stay together in the house and share monthly expenses equally. During their first month of living together, each person contributed Rs.25. At the end of the month, it was found that Rs 92 was the expense so the remaining amount was distributed equally among everyone. The distribution was such that everyone received a whole number of Rupees. How much did each person receive?

933


A student is ranked 13th from right and 8th from left. How many students are there in totality ?

878


Find the correct choice if the sum of any 4 consecutive numbers is divisible by a number?

822


5) DB2 maintains information about the data a) In Tables b) In a set of tables known as DB2 catalog c) In DB2 database d) None of the above

1762


X2 – (A-3)X +(A+3) = 0 for what value of A the sum of square of roots will be least ?

792


A man while going down in a escalator(which is moving down) takes 50 steps to reach down and while going up takes 125 steps. If he goes 5 times faster upwards than downwards. What will be the total no of steps if the escalator were'nt moving.

780