summaryrefslogtreecommitdiffstats
path: root/20
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-12-10 09:19:09 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-12-10 09:21:37 +0100
commit9f1080e091423531fab21ec0224368622580e92a (patch)
tree8131343e8f79d2e19e4cd55bd2c4b66af7dc51f4 /20
parent84dc757be6390492a5706756e45a17ab0a9d2b1d (diff)
downloadaoc-9f1080e091423531fab21ec0224368622580e92a.tar.gz
day 10
Diffstat (limited to '20')
-rw-r--r--20/README2
-rw-r--r--20/py/d10.py46
2 files changed, 48 insertions, 0 deletions
diff --git a/20/README b/20/README
index 907211d..b70ace7 100644
--- a/20/README
+++ b/20/README
@@ -11,6 +11,7 @@ Day Time Ans Time Ans
7 2.884 139 2.681 58175
8 0.263 2025 1.193 826
9 2.741 26796446 2.875 3353494
+ 10 0.027 2046 0.161 1157018619904
------- -------
tot TBD TBD
@@ -19,6 +20,7 @@ Stats:
-------Part 1-------- -------Part 2--------
Day Time Rank Score Time Rank Score
+ 10 00:08:17 1496 0 00:51:01 2766 0
9 00:25:55 6220 0 00:31:44 4392 0
8 00:08:21 1632 0 00:17:34 1265 0
7 00:55:51 5031 0 01:03:46 3520 0
diff --git a/20/py/d10.py b/20/py/d10.py
new file mode 100644
index 0000000..2b3bc2e
--- /dev/null
+++ b/20/py/d10.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+import aoc20
+import functools
+import sys
+
+
+def pt1(_in):
+ jolts = [int(n.strip()) for n in _in]
+ jolts.append(max(jolts)+3)
+ jolts = sorted(jolts)
+ jolt = 0
+ diffs = [0, 0, 0]
+ for j in jolts:
+ diffs[j-jolt-1] += 1
+ jolt = j
+ return diffs[0] * diffs[2]
+
+
+def pt2(_in):
+ jolts = [int(n.strip()) for n in _in]
+ jolts.append(max(jolts)+3)
+ jolts = sorted(jolts)
+ jolts.insert(0, 0)
+ jolt = 0
+ reach = {}
+ for i in range(len(jolts)):
+ reachable = []
+ j = i+1
+ while j < len(jolts) and jolts[j] - jolts[i] <= 3:
+ reachable.append(jolts[j])
+ j += 1
+ reach[jolts[i]] = tuple(reachable)
+
+ @functools.cache
+ def ways(start, dest):
+ if start == dest:
+ return 1
+ return sum(ways(child, dest) for child in reach[start])
+
+ return ways(jolts[0], jolts[-1])
+
+
+if __name__ == "__main__":
+ input = aoc20.read_input(sys.argv[1:], 10)
+ print(pt1(input))
+ print(pt2(input))