Chapter 1. Introduction

 

1. Write down the problem.

2. Think real hard.

3. Write down the solution.

 
 --"The Feynman Algorithm" as described by Murray Gell-Mann

Consider the following problem. You are to visit all the cities, towns, and villages of, say, Sweden and then return to your starting point. This might take a while (there are 24 978 locations to visit, after all), so you want to minimize your route. You plan on visiting each location exactly once, following the shortest route possible. As a programmer, you certainly don't want to plot the route by hand. Rather, you try to write some code that will plan your trip for you. For some reason, however, you can't seem to get it right. A straightforward program works well for a smaller number of ...

Get Python Algorithms: Mastering Basic Algorithms in the Python Language now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.