# Fly and Two Trains Riddle

Two trains travel on the same track towards each other, each going at a speed of 50 kph. They start out 100km apart. A fly starts at the front of one train and flies at 75 kph to the front of the other; when it gets there, it turns around and flies back towards the first. It continues flying back and forth till the two trains meet and it gets squashed.

How far did the fly travel before it got squashed?

The question is relatively simple - the trains take an hour to collide, and in an hour the fly would travel 75 km. However, the question got me wondering: Lets say you are given a time $t$ in hours(where $t< 1$) How many "rounds" would the fly make in $t$ time? A round is defined as moving from one train to another and back. How would I model the equation?

-
Infinitely many "rounds" are made in any situation that results in the trains crashing as above--as you've evidently noticed, given the tag. –  Cameron Buie May 25 '12 at 2:56
@Cameron. I'm not talking about the total amounts of rounds, but instead the amount of rounds over a specific amount of time. For example, the amount of rounds made in 30 minutes would be finite, wouldn't it?. Sorry, I should have clarified it in the question. –  user26649 May 25 '12 at 2:59
Ah! I see. Well, Marvis's answer should shed some light on the idea of this. Are you familiar with partial sums of a geometric series? If so, you can look at his answer with $a(1)=100$, then figure out the greatest $n$ for which the $n$th partial sum is less than the partial sum $$\sum_{t=1}^n\frac{a(t)}{125}=\sum_{t=1}^n\left(\frac{4}{5}\right)^t=-1+\cfrac{‌​1-\left(\frac{4}{5}\right)^{n+1}}{1-\frac{4}{5}},$$ assuming that Marvis calculated correctly. Is that what you were looking for? –  Cameron Buie May 25 '12 at 3:19
@CameronBuie Yes it was. Thanks! –  user26649 May 25 '12 at 3:46

The time taken to do the $n^{th}$ round is $\dfrac{a(n)}{(75+50)}$ where $a(n)$ is the distance between the two trains at the beginning of the $n^{th}$ round.

Note that $$a(n+1) = a(n) - (50+50) \times \dfrac{a(n)}{125} = \dfrac{a(n)}{5} = \dfrac{a(1)}{5^n}.$$ The distance travelled by the fly in the $n^{th}$ round is $75 \times \dfrac{a(n)}{125} = \dfrac{3}{5} a(n)$.

Hence, the total distance travelled by the fly is $$\sum_{n=1}^{\infty} \dfrac{3}{5} a(n) = a(1) \dfrac{3}{5} \left( 1 + \dfrac15 + \dfrac1{5^2} + \cdots \right) = a(1) \dfrac{3}{5} \times \dfrac{5}{4} = \dfrac34 a(1)$$ which is nothing but $$\text{Speed of the fly} \times \underbrace{\dfrac{a(1)}{\text{Relative speed between the trains}}}_{\text{Time taken by the trains to collide}}$$ which makes sense.

If you want the total number of rounds the fly makes before the train collides, this amounts to the number of rounds till when $a(n) = 0$. However note that only as $n \rightarrow \infty$, $a(n) \rightarrow 0$. Hence, the fly will make $\infty$-rounds before the trains collide!

The time taken by the fly to make the first round is $$\dfrac{a(1)}{125}.$$ The time taken by the fly to make the $n^{th}$ round is $$\dfrac{a(n)}{125}.$$ Hence, the time taken till the $N^{th}$ round is $$\sum_{n=1}^{N} \dfrac{a(n)}{125} = \sum_{n=1}^{N} \dfrac{ \dfrac{a(1)}{5^{n-1}}}{125}$$

Hence, solve for $N$ in the equation $$\sum_{n=1}^{N} \dfrac{ \dfrac{a(1)}{5^{n-1}}}{125} = t$$ Setting $a(1) = 100$, we get that $$\sum_{n=0}^{N-1} \left(\dfrac15 \right)^n = \dfrac{5t}{4}$$ $$\dfrac{\left(\dfrac15 \right)^N - 1}{\left(\dfrac15 \right) - 1} = \dfrac{5t}{4}$$ $$1 - \left(\dfrac15 \right)^N = t$$ $$\left(\dfrac15 \right)^N = 1-t$$ Hence the number of rounds, $N$, made by the fly as a function of time $t$ is $$N = \dfrac{\log(1-t)}{\log(1/5)}$$

-
Thanks, but I'm not looking for the total rounds, but the number of rounds made in a period of time less than an hour. I understand how the fly makes infinite rounds by the time it collides, but it would make a finite amount of rounds before collision. Am I mistaken? –  user26649 May 25 '12 at 3:05
I think the OP wanted in terms of $t$ the number of complete back and forth trips. This will be the greatest integer in an expression obtainable from your calculation. –  André Nicolas May 25 '12 at 3:05
@AndréNicolas Yes. Initially for some reason, I thought that Farhad was asking for total number of trips the fly would make. Now I understand and I have updated accordingly. –  user17762 May 25 '12 at 3:09
@FarhadYusufali I have badly messed up with the numbers. I will correct them soon :) –  user17762 May 25 '12 at 3:22
I want to take this opportunity to mention the famous (but not necessarily true) anecdote about the great mathematician von Neumann, who was also awesomely quick. Someone asked him the fly question, and he gave the right answer almost instantly. He was told "Oh, so you knew the trick." Von Neumann replied "What trick? I just summed the infinite series." –  André Nicolas May 25 '12 at 4:16