aboutsummaryrefslogtreecommitdiff
path: root/2015
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-12-04 00:28:12 +0100
committerThomas Voss <thomasvoss@live.com> 2021-12-04 00:28:12 +0100
commiteb34659683a52506f3bbea093dce131c410e955b (patch)
tree4569be6b5a9c21cc3af577698d5b2879b77ab8a9 /2015
parentd289467cf54104be14e9af352c924e93af2443dc (diff)
Add day 9 solutions
Diffstat (limited to '2015')
-rw-r--r--2015/09/.gitignore1
-rw-r--r--2015/09/Makefile8
-rw-r--r--2015/09/input28
-rw-r--r--2015/09/puzzles.py32
4 files changed, 69 insertions, 0 deletions
diff --git a/2015/09/.gitignore b/2015/09/.gitignore
new file mode 100644
index 0000000..ffc46fe
--- /dev/null
+++ b/2015/09/.gitignore
@@ -0,0 +1 @@
+puzzle-[12].py
diff --git a/2015/09/Makefile b/2015/09/Makefile
new file mode 100644
index 0000000..247194a
--- /dev/null
+++ b/2015/09/Makefile
@@ -0,0 +1,8 @@
+all:
+ sed '/START PART 2/,/END PART 2/d' puzzles.py >puzzle-1.py
+ sed '/START PART 1/,/END PART 1/d' puzzles.py >puzzle-2.py
+ chmod +x puzzle-[12].py
+
+.PHONY: clean
+clean:
+ rm -f puzzle-[12].py
diff --git a/2015/09/input b/2015/09/input
new file mode 100644
index 0000000..97a6b63
--- /dev/null
+++ b/2015/09/input
@@ -0,0 +1,28 @@
+Faerun to Tristram = 65
+Faerun to Tambi = 129
+Faerun to Norrath = 144
+Faerun to Snowdin = 71
+Faerun to Straylight = 137
+Faerun to AlphaCentauri = 3
+Faerun to Arbre = 149
+Tristram to Tambi = 63
+Tristram to Norrath = 4
+Tristram to Snowdin = 105
+Tristram to Straylight = 125
+Tristram to AlphaCentauri = 55
+Tristram to Arbre = 14
+Tambi to Norrath = 68
+Tambi to Snowdin = 52
+Tambi to Straylight = 65
+Tambi to AlphaCentauri = 22
+Tambi to Arbre = 143
+Norrath to Snowdin = 8
+Norrath to Straylight = 23
+Norrath to AlphaCentauri = 136
+Norrath to Arbre = 115
+Snowdin to Straylight = 101
+Snowdin to AlphaCentauri = 84
+Snowdin to Arbre = 96
+Straylight to AlphaCentauri = 107
+Straylight to Arbre = 14
+AlphaCentauri to Arbre = 46
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()