I love my electric car, but sometimes – like when I need to transport five people and a week’s worth of their luggage 250 miles and need to get there before the kids’ bedtime! – I still use our big ol’ diesel-burning beast. And it was while preparing for such a journey that I recently got to thinking about the mathematics of refuelling.

It’s rarely worth travelling out-of-your-way to get the best fuel prices. But when you’re on a long road trip *anyway* and you’re likely to pass dozens of filling stations as a matter of course, you might as well think at least a *little* about pulling over at the cheapest.

You could use one of the many online services to help with this, of course… but assuming you didn’t do this and you’re already on the road, is there a better strategy than just trusting your gut and saying “that’s good value!” when you see a good price?

It turns out this is an application for the Secretary Problem (and probably a little more sensible than the last time I talked about it!).

Here’s how you do it:

**Estimate your outstanding range**: how much further can you go? Your car might be able to help you with this. Let’s say we’ve got 82 miles in the tank.*R***Estimate the average distance between filling stations on your route,**. You can do this as-you-go by counting them over a fixed distance and continue from step #4 as you do so, and it’ll only really mess you up if there are very few. Maybe we’re on a big trunk road and there’s a filling station about every 5 miles.*D***Divide**: the number of filling stations you expect to pass before you completely run out of fuel. Round down, obviously, unless you’re happy to push your vehicle to the “next” one when it breaks down. In our example above, that gives us 16 filling stations we’ll probably see before we’re stranded.*R*by*D*to get*F***Divide**(use*F*by*e*to get*T**e*= 2.72 if you’re having to do this in your head). Round down again, for the same reason as before. This gives us*T*=5.**Drive past the next**Don’t stop for fuel at any of these.*T*filling stations and remember the*lowest*price you see.**Keep driving, and stop at the first filling station where the fuel is***the same price or cheaper*than the cheapest you’ve seen so far.

This is a modified variant of the Secretary Problem because it’s possible for two filling stations to have the *same* price, and that’s reflected in the algorithm above by the allowance for stopping for fuel at the same price as the best you saw during your sampling phase. It’s probably preferable to purchase sub-optimally than to run completely dry, right?

Of course, you’re still never guaranteed a good solution with this approach, but it maximises your odds. Your own risk-assessment might rank “not breaking down” over pure mathematical efficiency, and that’s on you.