Skip to content

Instantly share code, notes, and snippets.

@Ape
Last active December 9, 2015 15:15
Show Gist options
  • Save Ape/1146926033a2cf693d99 to your computer and use it in GitHub Desktop.
Save Ape/1146926033a2cf693d99 to your computer and use it in GitHub Desktop.
advent9.py
#!/usr/bin/env python3
import itertools
import sys
lines = (x.split(" ")[::2] for x in sys.stdin.readlines())
routes = {frozenset(x[:2]): int(x[2]) for x in lines}
places = set.union(*(set(x) for x in routes.keys()))
path_len = lambda path: sum(routes[frozenset(x)] for x in zip(path, path[1:]))
lengths = [path_len(x) for x in itertools.permutations(places)]
print(min(lengths))
print(max(lengths))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment