# The Fox and The Duck Question: A duck that is being chased by a fox saves itself by sitting at the center of circular pond of radius r. The duck can fly from land but cannot fly from the water. Furthermore, the fox cannot swim. The fox is four times faster than the duck. Assuming that the duck and fox are perfectly smart, is it possible for the duck to ever reach the edge of the pond and fly away to its escape from the ground?

Answer: One would think that the duck could swim directly away from the fox. So the duck would have to swim a distance r. The fox would have to cover half the circumference of the pond (pi * r). Since the fox is four times faster than the duck, we know that

(pi * r) < (4 * r)

This would make it seem like it is impossible for the duck to escape.

So how could the duck make life most difficult for the fox? If the duck just tries to swim along a radius, the fox could just sit along that radius and the duck would continue to be trapped.

The duck could swim in concentric circles, so that the fox has to continuously run along the circumference of the pond to stay on the same radius as the duck. If the duck swims near the edge of the pond, the fox could easily keep up since they would be covering approximately the same distance and the fox is four times faster. But what if the duck swam closer to the center of the pond? The duck would have to cover a smaller circumference, and could use this strategy to put some distance between the fox and itself. At a distance of r/4 from the center of the pond, the circumference of the pond is exactly four times the circumference of the duck’s path. Thus, to stay on the same radius as the duck, the fox would barely keep up.

Say, the duck circles the pond at a distance r/4 – e, where e is an infinitesimal amount. So as the duck continues to swim along this radius, it would slowly gain some distance over the fox. Once the duck is able to gain 180 degrees over the fox, the duck would have to cover a distance of 3r/4 + e to reach the edge of the pond. In the meanwhile, the fox would have to cover half the circumference of the pond (i.e the 180 degrees). At that point,

(pi * r ) > 4 * (3r/4 + e)

The duck would be able to make it to land and fly away.

Liked this question? Post this on Stumble, Twitter or Digg!

If you're looking for some serious preparation for your interviews, I'd recommend this book written by a lead Google interviewer. It has 189 programming questions and solutions:  ## 2 Responses

1. sailee says:

dis is awesum yr..

2. A question says:

Follow-up Question: Let the fox always instantly acquire top speed in attempting to acquire/maintain the same radius as the duck (along a shortest path to that radius). Assume that the duck swims the least distance possible before escaping (and can, like the fox, change directions instantaneously). How far does the duck travel before escaping?

Give this one a good long go before reading my solution. I might be wrong after all…who knows?

Answer: The obvious choice here for the path for the duck to take is for it always to move along the path that will keep exactly opposite the fox until it is exactly pi*r/4 from the shore, and then head straight for the shore to escape. Since the fox is always moving, the duck will always be swimming at some angle with respect to the direct radius it could travel, and this angle will approach 90 degrees as it approaches the circle of radius r/4.

To conclude this answer we need to create a function of the progress of the duck away from the center of the pond to determine how long it takes to reach its turn-off point, and then calculate the exact distance it would travel in that time.

Now, it’s clear that all the velocity the duck doesn’t spend moving to stay on the radius opposite the fox, it will spend moving closer to the distance from the center it needs to take off. Since the fox is always moving at top speed and traces a perfect circle, the duck has a constant angular velocity, and so its motion radially will decrease proportional to the rate at which the linear velocity increases as the radius increases, which is to say linearly.

Let’s call the angular velocity of the fox and duck a (in radians/sec). The fox’s actual speed is f and the duck’s is f/4. Note that a=f/r.

I’m gonna skip the calculus here, but it turns out that the duck’s path towards the limit circle of radius r/4 is a semicircle of radius r/8 centered at some point r/16 from the starting point.

Thus, to find the actual distance traveled, we need to find the point at which this semicircle is (4-pi)*r/4 from the center, which is the point said semicircle away from the starting point that is (4-pi)*r/4-r/8 above its own center. those, the portion of the semicircle inside this radius is pi/2+sin((4-pi)*r/4-r/8) radians by angle, which is the same value times pi/8 in distance.

Add pi*r/4 to this and you have the shortest distance the duck can travel in escaping the fox (unless I am somehow mistaken).

XHTML: These are some of the tags you can use: `<a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>`