Try now in the
Open Cloud »
(no sign-in required)

Shortest City Tours

In which order should you visit cities so as to travel the shortest distance?

Run the code to get a list of the capitals of Africa. Try other regions, like northern europe or the caribbean:

SHOW/HIDE DETAILS

Get a list of capitals of countries in Africa. Type += to get a natural language input box, and type capitals of africa into it. Run the code with +:

In[1]:=
X
Out[1]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Delete missing values:

SHOW/HIDE DETAILS

Some values may be missing:

In[1]:=
X
Out[1]=

Delete the missing values:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Get the geographic coordinates of the capitals. Try getting other properties, like Population or Elevation:

SHOW/HIDE DETAILS

Get the geographic coordinates of Paris. The result contains {latitude,longitude} coordinates:

In[1]:=
X
Out[1]=

Get the geographic coordinates of the capitals of Africa, and give it the name coordinates:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Find the order of capitals that gives the shortest route:

Note: run the code in the previous step first.

SHOW/HIDE DETAILS

Find the length of the shortest tour through all the capitals, and the order of the capitals along the route:

In[1]:=
X
Out[1]=

Extract just the order of the capitals on the shortest tour:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Show the order of the capitals along the shortest route:

Note: run the code in the previous step first.

SHOW/HIDE DETAILS

Reorder the elements of a list. Put the second element first, then the fourth, and so on:

In[1]:=
X
Out[1]=

Order the capitals of Africa along the shortest tour route:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Make a map of the shortest tour:

SHOW/HIDE DETAILS

Get the coordinates of the capitals in their order along the shortest tour route:

In[1]:=
X
Out[1]=

Make a map with a thick red line showing the shortest capital tour:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Share ItMake a website that shows the shortest route through cities that you specify:

SHOW/HIDE DETAILS

Deploy a form that asks for a list of cities and makes a map showing the shortest route through them. GeoRangePadding is used to add a margin around the route:

In[1]:=
X
Out[1]=

Click the link in the output to visit the site. Separate the cities you enter with semicolons (;) rather than spaces or commas, since both of those can occur in city names.

Share the link by right-clicking it and choosing Copy Address. Paste the link into an email, tweet, or other message.

HIDE DETAILS
In[1]:=
X
Out[1]=