I am co-hosting a mad comedy maths game show with Dara O'Briain on the TV channel Dave.

I was away filming for another series last week when an episode was aired that required some calculus. I got lots of tweets and emails about the problem so thought it worth just explaining how you solve it. It's got some great maths in it.

Problem: A lifeguard at the beach spots a swimmer in distress in the water. They need to run across the sand to the water and then swim out to rescue the swimmer. But what is the fastest path to take? If he can run twice as fast as he can swim, should he run as far as possible to swim the shortest distance possible? Or should he take a shorter path even if it involves more swimming? Here are the dimensions of the beach and locations of the lifeguard and swimmer.

Lets suppose the lifeguard's running speed is v1 and swimming speed is v2. The task is to find x which will minimise the time taken to travel along D1 and D2. The time taken is exactly T=D1/v1+D2/v2.

We note that v1=2*v2. Since v1 is a constant instead of minimising T we minimise v1*T i.e.
v1*T=D1 +2D2.
Now by Pythagoras D1=√(x^{2}+2^{2}) and D2=√((75-x)^{2}+25^{2}). To minimise v1*T we differentiate the right hand side with respect to x and set this derivative to zero. We solve for x and this gives us the critical value for x. Explicitly, once the maths is done we compute that x=60.58m. This you can get by Newton approximation method.

There is also a cute physical way you could use to solve this puzzle. Once you realise that you are having to minimise D1+2*D2 you can then take a piece of string which you run from the red spot round the yellow spot and then back to the point where the string crosses the dividing line. You then drag this point on the dividing line along the line and see where the string length is smallest. At x=60.58 you’ll get a point where suddenly you need more string to move in either direction.

When you set the differential to 0 and expand it then they will get a quartic polynomial. If you want to find the exact value (rather than an approximate value) then you are going to need to know how to find roots of a quartic! Also there are 4 solutions. Two are complex but there is another real solution at 89.43. This corresponds in the equation to taking different roots of the square root.

At school you learn about a formula for solving quadratic equations. There is also an extraordinary formula for solving quartic equations discovered by Italian mathematician Ferrari. Details are here. Feeding in the coefficients of our quartic gives the exact solution in the following form:

Glorious...if you like that kind of thing.

Why do we need to do quadratic equations at school? The problem Dara had to solve is an example where a problem of trying to find the optimal solution reduces to solving an equation. This one has x raised to the power 4 which we call a quartic. In school we learn how to solve a quadratic equation using a bit of algebra

Solving quadratic equations is something we do every time you catch a ball. If someone throws, kicks or hits a ball and you want to work out where to stand to catch it then the trajectory is described by a quadratic equation and solving it tells us where to stand. So Wayne Rooney is actually solving quadratic equations in his head every time he works out where to stand in the box to volley a ball in the back of the net.

This skill is very important in warfare too. If you want to hit a target then again you need to solve a quadratic equation to be able to decide the angle to fire the missile at.

We have been solving quadratic equations for millennia. The method we use dates back to ancient Babylon. The mathematicians of Babylon found a cunning way to solve these equations. They were interested in quadratic equations because they also describe areas of land.

But already in the tablets of ancient Babylon you can see people solving these equations not for practical reasons but for the fun of it. A quadratic equation is a bit like a cryptic crossword that hides the solution in some encrypted equation. Your challenge is to undo that cryptic description to reveal the answer to the puzzle.

The problem of finding a formula for solving cubics (things with x to the power 3) was one of the big challenges of the sixteenth century. Mathematical duelling was a public sport and great crowds would gather to watch mathematicians jousting with each other. Mathematicians would offer a cubic equation up and declare “solve that!” Tartaglia was an Italian mathematician who discovered the secret to solving these equations and made a lot of money in this public mathematical jousts. But he was tempted into revealing his secret to Cardano in exchange for the promise of future support. But Cardano betrayed his trust and told his student Ferrari who then saw how to generalize it to solving the quartic equation (x to the power 4 like in our problem). They published and poor Tartaglia lost the credit!

The problem of solving quintic equations (x to the power 5) turned out to be impossible with a simple formula and began the study of group theory which seeks to understand the world of symmetry.

You can find lots about this story in my book Finding Moonshine.

In order to find the value of x for which the time travelled is minimal we used the calculus. The calculus discovered by Newton and Leibniz is an extremely powerful tool for finding the optimal solution to practical problems. This idea of the power of the calculus to home in on the most efficient solutions to problems is one of the reasons it is a central tool in all modern science. It is used to do this day across the industrial and financial world. Investors use it to maximize profits. Engineers exploit it to minimize energy use. Designers apply it to optimize construction. It has now become one of the lynchpins of our modern technological world.

The calculus tries to make sense of what at first sight looks like a meaningless sum: what is zero divided by zero. Such a sum is what you are faced with calculating if you try to understand the instantaneous speed of an accelerating object. Take the famous apple that legend has it fell from the tree onto the young Newton’s head in the garden at Woolsthorpe and inspired his theory of gravity. The speed of the apple is constantly increasing as gravity pulls the apple to the ground. So how can you calculate what the speed is at any given instance of time. For example after one second how fast is the apple falling? Speed is distance travelled divided by time elapsed. So I could record the distance it drops in the next second and that would give me an average speed over that period. But I want the precise speed. Well I could record the distance travelled over a shorter period of time, say ½ a second or ¼ of a second. The smaller the interval of time the more accurately I will be calculating the speed. But ultimately to get the precise speed I want to take an interval of time that is infinitesimally small. But then I am faced with calculating 0 divided by 0. The invention of Newton’s calculus made sense of this calculation. He understood how to calculate what the speed was tending towards as you made the time interval smaller and smaller. It was a revolutionary new language that managed to capture a changing dynamic world. The geometry of the ancient Greeks was perfect for a static frozen picture of the world. But Newton’s mathematical breakthrough was the language that could describe a moving world. Mathematics had gone from describing a frozen still life to capturing a dynamic moving image. In our case we are trying to understand the behaviour of the distance D(1)+2D(2) as the distance x changes. If you draw a graph of this you get a curved graph. The calculus helps you to find the point where this graph reaches its minimum.

Work has been done by Timothy J. Pennings (Associate Professor of Mathematics at Hope College in Holland, Michigan) that suggests dogs are very good at finding such optimal solutions. See here and here Of course the dog isn’t really doing calculus (in the same way Wayne Rooney isn’t really solving quadratic equations) but it illustrates and important point that evolution has wired our brains to be good intuitive mathematicians. Those who can do maths survived. But it is by externalizing this maths that we can solve problems that defy our intuition.

The optimal path lifeguard is also the one light would choose if it travelled twice as fast in air as in water. In actual fact light travels only 1.33 times faster in air than in water so its path would be slightly different. However, this bending of the light waves (called refraction) produces many strange phenomena, such as making a straight pencil seem bent when it is put in water. Total internal reflection can be observed while swimming, if one opens one's eyes just under the water's surface. If the water is calm, its surface appears mirror-like. Another very common example of total internal reflection is a critically cut diamond. This is what gives it maximum sparkle.

The science behind this principle is known as Snell’s law. Snell's law states that the ratio of the sines of the angles of incidence and refraction is equivalent to the ratio of phase velocities in the two media. Using Snell’s law you can create total internal reflection. This occurs when, instead of light travelling from one substance to the next, the light reflects. This is a crucial physical phenomenon that allows us to use optical fibres. The light enters the plastic, and travels until it hits one of the walls. However, when it hits the wall, it is reflected instead of travelling through the clear plastic.