On this page
Imagine you are a lifeguard on a sandy beach. A swimmer is caught in the water diagonally down the shore from you.
Your first instinct might be to draw a straight line from your tower to the swimmer. That is the shortest distance. But you can run much faster on hard sand than you can swim through water. If you follow the straight line, you will spend too long fighting the waves. To minimise your time, you should run further down the beach to a point closer to the swimmer, reducing the time spent in the slow medium, before finally diving in.
This problem is a classic application of calculus. It is also the exact mechanism that governs how light travels through the universe.
What is the lifeguard problem?
The lifeguard problem is a mathematical exercise in finding the optimal point to transition between two different speeds.
To find this exact point, we have to balance two competing times. Let's say your running speed on the sand is v₁ and your swimming speed in the water is v₂. If you run a horizontal distance x along the beach, your time on the sand is the running distance divided by v₁. Your time in the water is the remaining swimming distance divided by v₂. The total time is the sum of these two phases.
When you take the derivative of this time equation and set it to zero, the result shows a perfect balance. The ratio of the sine of your angle on the sand (θ₁) to your running speed exactly matches the ratio of the sine of your angle in the water (θ₂) to your swimming speed:
sin θ₁ / v₁ = sin θ₂ / v₂
If you get stuck working out the derivative yourself, the Fermi Problem Library will walk you through the differentiation step by step rather than just printing the final equation.
How do you find the fastest path to run then swim?
Let's test this with a practical worked example. Suppose a lifeguard runs at 5 m/s and swims at 2 m/s. The swimmer is 40 meters out in the water and 100 meters down the beach. The lifeguard starts 30 meters inland on the sand.
The straight line: If the lifeguard aims straight for the swimmer, they cross the shoreline 42.9 meters down the beach. This path takes 45.3 seconds total (10.4 seconds running and 34.9 seconds swimming).
The fastest path: If the lifeguard instead runs 83.7 meters down the beach before jumping in, they run much further but swim significantly less. This takes 17.8 seconds of running and 21.6 seconds of swimming, for a total of 39.4 seconds.
Running further on the sand saves almost six seconds, which could easily be the difference between life and death.
This exact equation is Snell's Law of refraction. In 1662, Pierre de Fermat proposed that light traveling between two points takes the path that requires the least time (Fermat's principle). When light moves from air (where it travels quickly) into water (where it travels more slowly), it bends its path towards the normal. You can set up different speeds and observe how the optimal path bends in the Fermi Simulation Lab.
This is why a straw looks bent in a glass of water, and it is the same rule that dictates refraction through a glass sphere. Light "chooses" to spend more distance in the fast medium to minimise the overall time of the journey.
Of course, a ray of light does not consciously calculate its route. Later physicists discovered that light behaves as a wave. As the wavefronts ripple outward, the waves taking neighboring, non-optimal paths interfere with and cancel each other out. The only path where the light waves constructively reinforce one another is the path of stationary time. The "choice" is simply the natural geometry of wave propagation.
Do dogs know calculus?
While human mathematics students use derivatives to find the absolute minimum on an interval, animals often solve this optimization problem by instinct.
In a 2003 study published in The College Mathematics Journal, mathematician Timothy J. Pennings tested this theory with his Welsh Corgi, Elvis. By throwing a tennis ball into Lake Michigan, Pennings measured Elvis's choices. Elvis ran along the beach at 6.4 m/s and swam at 0.9 m/s.
Because his running speed was about seven times his swimming speed, the optimal strategy was to run almost entirely down the beach before jumping in. Across 35 throws, Pennings found that Elvis consistently ignored the straight-line path. Instead, the dog plunged into the water at an angle that closely matched the mathematical optimum predicted by Snell's Law.
Whether it is a ray of light crossing a boundary, a dog fetching a ball, or a lifeguard on a rescue mission, the universe heavily favours the path of least time.



