Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'll try it. I hope I do not make a stupid mistake.

When the first train has travelled one third of the distance separating it from the other train, the fly will have travelled two thirds of this distance, and the other train one third of the distance, in the opposite way, which means it is exactly the moment at which the fly hits the second train and turns back.

Let d be the initial distance between both trains. Now we are solving almost the same problem (the speeds do not change, and the way the fly travels is irrelevant, the problem is symmetric), the only parameter changing is the distance, now being 2/3 * d.

We can reason the same way ad infinitum and we identify the distance D travelled by the fly is the following:

D = 2/3 d + 2/3 (2/3 d) + ... D = 2/3 d + (2/3)^2 d + (2/3)^3 d + ... D = d * {sum for n from 1 to infinity}{(2/3) ^ n} D = 3d

The fly travels 3 times the distance between the trains before dying.



Indeed, doing the infinite sum is the "hard" way.

The easier way is to notice that the trains will collide in 1h and the fly will be constantly be flying at a speed of 60mph for the entire time. So the fly will travel 60 miles in the alloted time.


It means I actually made a mistake! I understand your solution. :)


Yeah, the distance changes by a factor of 1/3 each time (which actually makes for an easier infinite sum), not 2/3.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: