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
The length and breadth of a rectangle are increased by 20% and 40% respectively. What is the percentage increase in its area?
The price of coffee increases by 20%, how much percent consumption of coffee should be reduced by Reema so that the expenditure on coffee remains the same.
hi had any body attended bank of interview plz........ share your experience
A wizard named Nepo says "I am only three times my son's age. My father is 40 years more than twice my age. Together the three of us are a mere 1240 years old." How old is Nepo?
12 Blacksox and 12 Whitesox mixed in a box,a pair of sox is picked at a time,in which pick how many pick ,to get the right pair(black&black or white&white)?
In the given figure, PA and PB are tangents to the circle at A and B respectively and the chord BC is parallel to tangent PA. If AC = 6 cm, and length of the tangent AP is 9 cm, then what is the length of the chord BC?
A person left house with speed 40 mile per hour his wife after 30 minutes left to catch him at a speed of 50. In what time she will catch?
How many 3-digit numbers will be there which are divisible by 19?
A son and father goes for boating in river upstream . After rowing for 1 mile son notices the hat of his father falling in the river. After 5min. he tells his father that his hat has fallen. So they turn around and are able to pick the hat at the point from where they began boating after 5 min.Tell the speed of river.
Complete the series 1 6 3 7 5 8 7 ?
there are 76 persons. 53 can read hindu,46 can read times,39 can read deccan and 15 can read all.if 22 can read hindu and deccan and 23 can read deccan and times then what is the number of persons who read only times and hindu………
There is a room with 6' x 8'. A 1' tile is fixed along the 4 walls in one row. How many 1" tiles require to finish the work.
A,B,C,D,E are some numbers.if AB * CD = EEE and CD - A =CC THEN what is AB * D =? IN SAME CODE .
There is a work which can be completed by A with 12 days and B by 18 days. A and B works together for 3 days and B left. After that how many days for A to complete the work?
If g (0)=g (1)=1 And: g (n)= g (n-1) + g (n –2) find g (6);