diff options
Diffstat (limited to 'day9.py')
-rw-r--r-- | day9.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/day9.py b/day9.py new file mode 100644 index 0000000..4ce3f69 --- /dev/null +++ b/day9.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +from collections import defaultdict +from itertools import permutations + +graph = defaultdict(lambda: defaultdict(int)) +with open('day9.txt') as data: + for line in data: + pos1, _, pos2, _, dist = line.strip().split() + graph[pos1][pos2] = int(dist) + graph[pos2][pos1] = int(dist) + +routes = list(permutations(graph.keys())) + +def route_dist(route): + dist = 0 + for i in range(len(route)-1): + dist += graph[route[i]][route[i+1]] + return dist + +minDist, maxDist = float('inf'), 0 +for route in routes: + dist = route_dist(route) + if dist < minDist: + minDist = dist + if dist > maxDist: + maxDist = dist +print(minDist) +print(maxDist) |