I was told an example interview question involving ants following one another around in a square, and it continued to bug me for a while (pun wholeheartedly intended). The specific wording of the problem is this:
4 ants are place at the corners of a square of unit area, and each ant walks towards the ant ahead of it. What is the shape of the path the ants take, and how far do they walk until they meet?
Sounds fun and relatively simple (though not so much in an interview situation!), lets have a look.
Now, due to the symmetry of the problem we can just focus on one ant as it follows its neighbour ahead of it – pick the rightmost ant as depicted below, and assign it polar coordinates . I’ve drawn the starting positions of the 4 ants, and how 2 of them have moved after a short time, say .
We’d need to find the path of the ant, so we need to know how changes as a function of . The direction of motion is always towards the next ant which is moving in the same way but rotated by , so it should be fairly obvious that all 4 ants continue to remain on the corners of a square as it rotates and shrinks and they gradually meet each other. The paths should look like a spiral then, and we expect the ants to meet in the middle.
If we zoom in slightly and add some notation, we can decompose the displacement vector along the and directions. In this geometry the displacement vector is always at from the direction of increasing , and this stays the same as the ants walk towards one another.
Decomposing displacement components then, we have in some small time period (assuming unit velocity, we’re only concerned in relative displacements so the velocity doesn’t matter)
If we then take the limits , we end up at the nice and simple differential equation
which I’m sure 9 of 10 people you meet in the street would be able to solve. We’ve assumed a unit square, so the initial ant radius at is , and the solution is
which is surprisingly simple, and much simpler than had we tried cartesian coordinates. The setup of the problem is perhaps designed to encourage a cartesian approach, where I’m sure the poor interviewee would get quickly bogged down in an awful differential equation to solve.
It is interesting to note that this is a logarithmic spiral which is self-similar (another type of fractal?) and occurs throughout nature
We can animate the ants now, and its clear that, as we argued, they stay on the vertices of a square as they spiral inwards.
Finally, to solve the problem and get our job shepherding insects, we have to work out the path length . This is simple now we have all the relevant information, we know we’re going from to so we just have to perform the integral
So, after all that we end up, of course, at 1. There are only two numbers in physics, 1 and , so in hindsight perhaps it would have been prudent to guess one of these and bask in our adulation when we were correct. However, this might not have made for a satisfactory interview and surely a follow-up question would be inbound imminently. Well, lets prepare for just such an occasion! We just dealt with the situation of 4 ants on a square, so naturally we should try and generalise this result. What about regular triangles, pentagons, circles etc?
Again we can exploit the symmetry of the problem and just focus on one ant. The only thing that has changed now is the angle the displacement vector makes with the increasing- vector:
We’ve assumed a regular N-sided polygon (an N-gon), which means the ants are distributed round in steps of , i.e. for a square N=4 and the steps are as in the previous diagram. The new equations for changes in and are then
for some initial radius . How should we compare these N-gons? If we stick with 1 unit to a side they will rapidly become much larger than our initial square and the results won’t be comparable. We’ll stick with the requirement that the area of the N-gon is 1 unit, which leads to the requirement for that
so finally the expression for the paths the ants take for our unit area N-gons becomes
and of course if we set N=4 we recover the previous expression. We can churn through the same algebra as before to find the path length too
This is a nice and simple formula that, again, reduces to 1 if we select N=4. We can plot this out to see how it varies, and if we were to allow noninteger N (whatever that means…) there are actually 2 solutions for a unit path length.
There is a minimum between a triangle and square, but it doesn’t occur at 1 or so I have no idea how to work that out. Actually its the solution to an algebraically unsolvable equation, so there’s not much to be learnt there. As N increases and the path length increases without limit. This makes sense, as the shapes become more and more circular the spirals become more and more shallow and eventually the poor ants are just wandering around in circles. At this point in the interview, which I assume is for some kind of bug exhibit at the zoo, you should of course decry this inhumanity of the poor ants (inhumantity?) forever walking in circles and storm out. Not before showing the following fancy animation to prove your newfound anti-aliasing skills though.