## Interview Question

## Interview Answer

8 Answers

Ants are never going to meet. because by the time 1 reaches 2 , 2 will reach 3 and 3 will reach 1. so they are never going to meet. :)

Here is the same problem but on a square rather than triangle: http://www.mytechinterviews.com/chasing-dogs

Here is the solution on youtube Three Ants - Solution https://www.youtube.com/watch?v=YCWgOsgPYBw

Also asked using Mice http://mathworld.wolfram.com/MiceProblem.html

The first inclination is to say that they'll never meet, because it's easy to consider the inside of the triangle off limits, but when answering a quest like this it's important to consider all of the possibilities. You should always ask questions like "Can the ants move on the inside of the triangle?" to get all of the available information. Here's one good example explaining how long and how far the ants would travel: https://www.youtube.com/watch?v=YCWgOsgPYBw

I'm not sure if I understand the question... if it's just ants moving to the midpoint of the triangle -- you could do it geometrically, or if you were given cartesian coords it's even easier. the mid point is the average of the points. so: mid.x = (x0 + x1 + x2)/3 mid.y = (y0 + y1 + y2)/3 knowing the mid point the distance is simply the distance between the midpoint and any other point. Applying the distance formula: distance = sqrt((mid.x - p.x)^2 + (mid.y-p.y)^2) now we have distance, and velocity and we wish to find time. velocity is in units of meters/sec. distance is in meters we need to solve for seconds. so we divide the distance traveled by the rate, and our units cancel which gives us time.

> I'm not sure if I understand the question... if it's just ants moving to the midpoint of the triangle Read it again. Each ant moves towards the next ant, not directly towards the center. Their paths describe a spiral arc and they meet at the center eventually, but not via a straight line. Look at the links to solutions.

## Add Answers or Comments

To comment on this, Sign In or Sign Up.

I couldn't come up with a good answer, don't know if I am weak in geometry, calculus, logic, or just not smart enough.