Next | You can't get there from here | 27 |
sub travelling_salesman { my ($cities, $airfare, $budget) = @_; for my $itinerary (all_permutations($cities)) { if (cost_of($airfare, @$itinerary) < $budget) { return $itinerary; } } return undef; }
How long does this take?
There are a lot of possible itineraries
3 6 4 24 5 120 6 720
7 5,040 8 40,320 9 362,880 10 3,628,800
continued...
Next | Copyright © 2005 M. J. Dominus |