About cows and flies.

Once upon a time there was a cow. Her name was Mary.

This cow had a friend. It’s good to have friends in life! Her friend was a fly.

They wanted to go from the stable to the meadow, together. The meadow was 5 kms from the stable. Mary, being a cow and all, moved slower than her friend, the fly. She walked at a speed of 1 km/h. The fly, being a fly and all, was hyper-active and never stopped flying. It flew at a speed of 10 kms/h.

Obviously, the fly got to the meadow much faster that Mary. But being hyper-active and a friend, it got back to meet Mary, who had started the walk and was somewhere on the way. Then the fly flew back to the meadow again, and then back to Mary, who had advanced a little more. And it kept doing this until Mary reached the meadow.

Can you tell the total distance that the fly flew?

I’ll give you time to think while I explain my motivation for putting this problem here (and maybe giving you a hint). This problem was proposed by my professor on today’s class. We were studying the formal verification of programs, and after lots of examples and formalities and students sleeping he just went to the black board and started telling Mary’s story. It was quite surprising and he made his point pretty well, which was: the importance of invariants.

Now, do you know the answer already?

You might have thought that this is series problem, and that you would have to define a recursive relation based on distance and time and speed of Mary and the fly. This is a possible solution (that I did not dare to try during class). But check out the pretty solution.

In this problem, what is invariant for Mary and the fly? They leave the stable and arrive at the meadow at the same time! Of course that Mary arrives only once, while the fly arrives several times. But the question wants to know the distance flown by the fly after both reached the meadow, or, after the fly arriving at the meadow for the last time. Now this fly was flying frenetically for the entire time Mary took to get to the meadow, which was? 5 hours (5 kms at the speed of 1 km/h). So the fly flew for 5 hours at its speed, which was 10 kms/h. Answer: they fly flew 50 kms.

Nice, isn’t it?