ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Aptitude Questions  >>  General Aptitude
 
 


 

 
 English interview questions  English Interview Questions
 General Aptitude interview questions  General Aptitude Interview Questions
 Puzzles interview questions  Puzzles Interview Questions
Question
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
 Question Submitted By :: Nandita
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
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 ?    0 Yes 3 No
Sanket
 
  Re: 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
# 2
D answer sanket may be wrong. U gotta program both the chips.
and u cant say "MB(T1)" to train T2 and viceversa, neither
"IF(T1 at P1)". There is no way for the trains to know where
they are.
My answer is:
MF;
i=1;
do
{
for(j=1;j<=(i*2)+1;j++)
   MB;
for(j=1;j<=(i*2)+2;j++)
   MF;
}While(1);

This causes both the trains to oscillate about their
respective parachutes,moving a unit length longer in forward
and backward direction for each oscillation. sure, they
gotta BUMP into each other.

My assumption:
Usual programming language constructs can be used.
Given Commands are just for controlling the train.
 
Is This Answer Correct ?    0 Yes 1 No
Rajasekar B
 
 
 
  Re: 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
# 3
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 ?    1 Yes 0 No
Rshadow
 
  Re: 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
# 4
After I was asked this question (two weeks after my comment
#3) in a job interview and was guided to the solution - not
before I tried to give the oscillating solution from comment
#2 above, which can't be coded within the limitation of the
4 available commands - I give here the correct and final answer:

start:
MF
MF
MB
if (p) GOTO found
GOTO start
found:
MF
GOTO found

Explanation:
Both trains start moving in the same direction at the same
rate. After one train meets the parachute of the other
train, it starts going at a faster rate and thus will catch
up with the other train and bump into it.

It's a simple solution, but not that easy to come up with.
Seems to be a popular question in job interviews for
programmers in high-tech companies in Israel (me and a
friend were each asked this riddle at a job interview, in
two different companies).
 
Is This Answer Correct ?    2 Yes 0 No
Rshadow
 

 
 
 
Other General Aptitude Interview Questions
 
  Question Asked @ Answers
 
if the length of the rectangle is reduced by 20% and breath is increased by 20 % what is the net change ? Verifone1
In a class of 40 students, 24 students speak Hindi and 20 students speak Kannada. Eight students speak none of the two languages. How many students speak both Hindi and Kannada? Infosys19
In 1978, a kg of paper was sold at Rs25/-. I f the paper rate increases at 1.5% more than inflation rate which is of 6.5% a year , then what wil be the cost of a kg of paper after 2 years? a)29.12 (b) 29.72 (c) 30.12 (d) 32.65 (e) none of these IBM3
What is the equivalent compound ratio of 5:6::7:10::6:5? Accenture15
minutes hand gains 45% at 11.20 p.m. so finally what is % of time gained by minutes hand TCS3
Find the area not occupied by circles: Given length =y breadth =x CTS2
If PQRST is a parallelogram what it the ratio of triangle PQS & parallelogram PQRST CMC1
a person left house with speed 40 mile per hour. His wife after 30 minutes left to catch him at a speed of 50 Miles Per Hour. in what time she will catch. COSL2
in a group,except 18 above 15 yrs of age and 15 r below 50 yrs of age..how many in that group Oracle2
. In june a baseball team that played 60 games had won 30% of its game played. After a phenomenal winning streak this team raised its average to 50% .How many games must the team have won in a row to attain this average?  3
In 1000 wine bottles stack 10 are poisoned given 10 rats what is the minimum number of tries to find the poisoned one. Rat dies once it licks the poisoned wine. Yahoo8
In a class , except 18 all are above 50 years. 15 are below 50 years of age. how many people are there a) 30 b) 33 c) 36 d) none of these. IBM5
A traveler walks a certain distance. Had he gone half a kilometer an hour faster , he would have walked it in 4/5 of the time, and had he gone half a Kilometer an hour slower, he would have walked 2 ½ hr longer. What is the distance? TCS1
In a certain department store, which has four sizes of a specific shirt, there are 1/3 as many small shirts as medium shirts, and 1/2 as many large shirts as small shirts. If there are as many x-large shirts as large shirts, what percent of the shirts in the store are medium?  2
. One train leaves Bangalore at 15 kmp heading for Mysore. Another train leaves from Mysore at 20kmp heading for Bangalore on the same track. If a bird, flying at 25kmp, leaves from Bangalore at the same time as the train and flies back and forth between the two trains until they collide, how far will the bird have traveled? Wipro4
which one of following group animals are primates CDS1
45% of 1500 + 35% of 1700 = ?% of 3175 (a) 40 (b) 55 (c) 45 (d) 35 (e) None of these  1
There are two circles, one circle is inscribed and another circle is circumscribed over a square. What is the ratio of area of inner to outer circle? 3i-Infotech3
1/8 is devided by 's' , if 's' is incresed by 2 times, what is the result. Wipro9
12 revolutions takes 1/8 th second time.In 20 seconds how many revolutions? CitiGroup5
 
For more General Aptitude Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com