Chapter 9 is genetic algorithms. The book evolves toward a fixed target phrase; this expansion evolves a real optimization, the traveling-salesman tour of world capitals.

The genome is a visiting order over 22 capitals. Fitness is the total haversine (great-circle) distance of the loop, so shorter tours win. Breeding uses ordered crossover, which preserves a run of cities from one parent and fills the rest from the other without repeats, and mutation swaps two stops. The best tour each generation is drawn over an equirectangular map, and you can watch the route untangle itself across real geography as the kilometer count drops.

Data source: Curated capital coordinates
Endpoint: No live API. REST Countries (restcountries.com) was deprecated in 2025.
Access: Public, no key. Loaded from an hourly server-side refresh when possible, with a bundled snapshot fallback, and a live browser fetch only when the API allows CORS. Data window: Curated capital coordinates (static list; pulled Jul 18, 2026 UTC)

REST Countries, the API I originally planned to pull capitals from, was deprecated in 2025, so the coordinates are a curated list. The distances are still real great-circle kilometers.

The 22 capitals in the tour are Washington, Ottawa, Mexico City, Bogotá, Brasília, Buenos Aires, London, Paris, Madrid, Berlin, Rome, Moscow, Cairo, Nairobi, Pretoria, Lagos, Delhi, Beijing, Tokyo, Jakarta, Canberra, and Wellington. They are spread across six continents so the shortest loop has to make deliberate ocean crossings rather than hugging one region.