11 my ($src, $dst, $len) = /^(\w+) to (\w+) = (\d+)/;
12 $cities{$src} = $cities{$dst} = 1;
13 $route{$src,$dst} = $len;
14 $route{$dst,$src} = $len;
20 my ($path, $dist, $rest) = @_;
23 $min_dist = $dist if !$min_dist || $dist < $min_dist;
24 say "new min $min_dist";
27 for my $i (0 .. $#$rest) {
29 my ($next) = splice (@nrest, $i, 1);
30 my @npath = (@$path, $next);
33 my $prev = $path->[-1];
34 $ndist += $route{$prev,$next};
36 # say join(',', @npath), " $ndist";
37 do_perm(\@npath, $ndist, \@nrest);
41 do_perm([], 0, [ keys %cities ]);