/ Python / 2015 / 09.py
09.py
 1  from lib import *
 2  
 3  input = read_input(2015, 9)
 4  
 5  
 6  graph = {}
 7  for src, _, dst, _, dist in map(str.split, input.splitlines()):
 8      graph.setdefault(src, {})[dst] = int(dist)
 9      graph.setdefault(dst, {})[src] = int(dist)
10  
11  
12  print(min(sum(graph[a][b] for a, b in zip(locs, locs[1:])) for locs in itertools.permutations(graph)))
13  print(max(sum(graph[a][b] for a, b in zip(locs, locs[1:])) for locs in itertools.permutations(graph)))