A Tesla Motors Inc. Gallery And Service Center As Stock Rebounds
Tesla supercharger stations. Bloomberg via Getty Images

This is the perfect Tesla Supercharger roadtrip

Jun 16, 2015

If you're looking to hit every single Tesla Supercharger station in the U.S., this data scientist has you covered.

Mortada Mehyar set out to solve what's known as the "traveling salesman problem," a complicated mathematical puzzle that aims to determine the perfect (meaning shortest) path for a person visiting a set of destinations: In this case, Tesla Model S charging stations. Given all the possibilities, the calculation can be algorithmically baffling, even for computers.

For instance, if there are two hundred stations would require checking, according to the programmer, approximately 7.9 x 10^134 permutations. Suffice it to say that that is A LOT of permutations. "That's actually a lot more than the total number of atoms in the universe!" he writes.

Luckily, there's a better way to solve the problem. Mehyar uses a program called Concorde that whittles down the possibility space by using algorithm branches, allowing it figure out what is closest to an exact optimum path as possible. "Since we don't have that many nodes, and the distance metric (symmetric geometric distance) is relatively simple," the coder said. Exactness is his goal.

At the time of the writing of the post, there were 194 superchargers across the country, he said. After crunching the numbers, he finds the route below to be the best:

Perfect Tesla Supercharger Roadtrip 2015 Courtesy of Mortada Mehyar. 

Presumably, Mehyar has reverse engineered a logistical problem that Elon Musk is no doubt grappling with at his electric car company. "Stations are strategically placed to minimize stops during long distance travel," the company's website says.

Tesla (tsla) has been expanding rapidly, however, dotting the country with its recharge posts. Already the course plotted by Mehyar is slightly out of date. At the time of writing this post, there were two more supercharger locations in the U.S., bring the total up to 196.

Pack an extra pair of socks.

All products and services featured are based solely on editorial selection. FORTUNE may receive compensation for some links to products and services on this website.

Quotes delayed at least 15 minutes. Market data provided by Interactive Data. ETF and Mutual Fund data provided by Morningstar, Inc. Dow Jones Terms & Conditions: http://www.djindexes.com/mdsidx/html/tandc/indexestandcs.html. S&P Index data is the property of Chicago Mercantile Exchange Inc. and its licensors. All rights reserved. Terms & Conditions. Powered and implemented by Interactive Data Managed Solutions