For a delivery truck making rounds, minor tweaks in a route can save huge amounts of time and gas. That’s why UPS spent a decade and hundreds of millions of dollars building an algorithm to help calculate where trucks should turn. A startup called Routific designed an algorithm to help everyone else–like local flower delivery companies–also save fuel.

To help find the best routes, they took inspiration from bees. Their algorithm is based on the “bees algorithm,” which describes how bees find the best route to flowers. Scout bees fly long distances in random directions, and if they find food, they fly back and buzz around in the so-called “waggle dance” to notify everyone else. When others go to the same location, they’ll come back and waggle even harder if they find a better spot.

It’s a way for bees to very quickly find the best food sources, and a similar approach works for a delivery company trying to figure out which route to take. This is not necessarily the perfect route, because calculating the perfect route could take days. But it’s the best route that can be found in a short amount of time.

“If you have 57 stops, there are already more than a quattuorvigintillion possible combinations,” says Marc Kuo, founder and CEO of Routific. “That’s one with 75 zeros. A very basic algorithm that is going to churn through every possible combination and select the best one, that is going to take you days if not months for a computer.”

Instead, the company’s software churns through the data in a smarter way. “The ones that seem promising, then attract more computational power, similar to the bees–the ones that seem more promising, they will do a waggle dance. So it’s deeper in that particular area. When you get in that particular area you can then find an optimized route that way.”

Right now, a traditional delivery company still plans out routes by hand. “Let’s say they have 20 trucks and 1,000 addresses,” he says. “Somebody at the office, every morning, they spend two to three hours just assigning those addresses to the trucks and manually ordering them just by eyeballing it on a map.”

Not only does it take time, it’s not an easy problem for humans to solve–you’re not just thinking about the roads, but whether a particular customer needs a delivery in a certain time window, or how much can fit on each truck. When an algorithm crunches that data instead, it performs so much better that it saves 40% on driving time and fuel.