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
If log 0.317=……… and log 0.318=………. Then find the value of log 0.319.
Suhana gets 70% in Maths, 80% in Physics. To get an overall of 75% how much should she get in English.
Olympic race : 4 contestants : Alan,charlie, Darren ,Brain. There are two races and average is taken to decide the winner.one person comes at the same position in both the race. Charlie always come before darren. Brian comes first once. Alan comes third at least once. Find the positions. Alan never comes last. Charlie & darren comes 2nd at least once.
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
(998-1)(998-2)(998-3).....(998-n)= ? when n>1000
the sum of the present ages of a father and his son is 60 years. Six years ago, father's age was five times the age of the son. After 6 years, son's age will be?
Respected Sir/Mem Plz send me all 5 years solved question papers of sbi clerk on my Gmail id and that is chandelmishel@gmail.com
A person travels 6km towards west, then travels 5km towards north ,then finally travels 6km towards west. Where is he with respect to his starting position?
There are 1000 junior and 800 senior students in a class. And there are 60 sibling pairs where each pair has 1 junior and 1 senior.1 student is chosen from senior and 1 from junior randomly.What is the probability that the two selected students are from a sibling pair?
If a car starts from A towards B with some velocity due to some problem in the engine after travelling 30km.If the car goes with 4/5 th of its actual velocity the car reaches B 45min later to the actual time. If the car engine fails after travelling 45km, the car reaches the destination B 36min late to the actual time , what is the initial velocity of car and what is the distance between A and B in km
im swetha... is the chances 4 science graduates are less when compared with arts & commerce graduates 4 a bank job? why im asking bcoz, i attended for four banks interview like sbi[2], bank of baroda, karur vysya bank after selected in the written test. i attended interview very well. but not.. why this?
One Train Travels 200m From A To B With 70 Km/Ph And Returns To A With 80kmph, What Is The Average Of Their Speed?
25 stations ,24 stations are inbetween- - - - - how many tickets should be required.
Which countries have two official national anthem ?
In a club there are male and female members. If 15 female quit then the number of males will become double the number of males. If 45 males quit no. of female becomes five times the number of males. Find the number of females.