From eb34659683a52506f3bbea093dce131c410e955b Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 4 Dec 2021 00:28:12 +0100 Subject: Add day 9 solutions --- 2015/09/puzzles.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 2015/09/puzzles.py (limited to '2015/09/puzzles.py') 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() -- cgit v1.2.3