aboutsummaryrefslogtreecommitdiff
path: root/2015/09/puzzles.py
diff options
context:
space:
mode:
Diffstat (limited to '2015/09/puzzles.py')
-rw-r--r--2015/09/puzzles.py32
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()