summary refs log blame commit diff stats
path: root/day9.py
blob: 4ce3f69391b33d4a5b99d63cb3c034e7370a12ee (plain) (tree)




























                                                     
#!/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)