| Next | You can't get there from here | 31 |
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
15 118,879,488,000
20 221,172,909,834,240,000
continued...
| Next | ![]() |
Copyright © 2005 M. J. Dominus |