diff options
author | Thomas Voss <thomasvoss@live.com> | 2021-12-04 00:28:12 +0100 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2021-12-04 00:28:12 +0100 |
commit | eb34659683a52506f3bbea093dce131c410e955b (patch) | |
tree | 4569be6b5a9c21cc3af577698d5b2879b77ab8a9 /2015/09/puzzles.py | |
parent | d289467cf54104be14e9af352c924e93af2443dc (diff) |
Add day 9 solutions
Diffstat (limited to '2015/09/puzzles.py')
-rw-r--r-- | 2015/09/puzzles.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/2015/09/puzzles.py b/2015/09/puzzles.py new file mode 100644 index 0000000..e0d33b7 --- /dev/null +++ b/2015/09/puzzles.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import itertools +import re + + +def main() -> None: + towns: set[str] = set() + distances: list[tuple[str, str, int]] = [] + with open("input", "r", encoding="utf-8") as f: + for line in f.readlines(): + f, t, d = re.match(r"(\w+) to (\w+) = (\d+)", line).groups() + towns.update({f, t}) + distances.append((f, t, int(d))) + + print( + # START PART 1 + min( + # END PART 1 START PART 2 + max( + # END PART 2 + sum( + [d[2] for d in distances if part[0] in d and part[1] in d][0] + for part in zip(perm, perm[1:]) + ) + for perm in itertools.permutations(towns) + ) + ) + + +if __name__ == "__main__": + main() |