summaryrefslogtreecommitdiff
path: root/day10
diff options
context:
space:
mode:
authorCody Hiar <cody@hiar.ca>2021-03-05 12:31:00 -0700
committerCody Hiar <cody@hiar.ca>2021-03-05 12:31:00 -0700
commit54998c7452e423a6aa7deef3047f0c334c3272f6 (patch)
tree36e5bbe4e144b49b6e842196c7785d673b218fea /day10
parent872cf02664b8979a0b22b394bf239941774028d8 (diff)
Updating till day 10
Diffstat (limited to 'day10')
-rw-r--r--day10/day10.py28
-rw-r--r--day10/input96
2 files changed, 124 insertions, 0 deletions
diff --git a/day10/day10.py b/day10/day10.py
new file mode 100644
index 0000000..041c758
--- /dev/null
+++ b/day10/day10.py
@@ -0,0 +1,28 @@
+"""Day 10."""
+from collections import Counter
+from itertools import combinations
+from functools import lru_cache
+
+with open("input") as f:
+ orig_nums = sorted([int(x) for x in f.read().rstrip().split("\n")])
+
+rated_for = orig_nums[-1] + 3
+nums = [0] + orig_nums + [rated_for]
+diffs = [j - i for i, j in list(zip(nums[:-1], nums[1:]))]
+counter = Counter(diffs)
+
+# Part 1
+print(counter[1] * counter[3])
+
+@lru_cache(None)
+def arrangements(jolts, prev) -> int:
+ first, rest = jolts[0], jolts[1:]
+ if first - prev > 3:
+ return 0
+ elif not rest:
+ return 1
+ else:
+ return (arrangements(rest, first) + # Use first
+ arrangements(rest, prev)) # Skip first
+
+print(arrangements(tuple(orig_nums), 0))
diff --git a/day10/input b/day10/input
new file mode 100644
index 0000000..4a713ff
--- /dev/null
+++ b/day10/input
@@ -0,0 +1,96 @@
+99
+3
+1
+11
+48
+113
+131
+43
+82
+19
+4
+153
+105
+52
+56
+109
+27
+119
+147
+31
+34
+13
+129
+17
+61
+10
+29
+24
+12
+104
+152
+103
+80
+116
+79
+73
+21
+133
+44
+18
+74
+112
+136
+30
+146
+100
+39
+130
+91
+124
+70
+115
+81
+28
+151
+2
+122
+87
+143
+62
+7
+126
+95
+75
+20
+123
+63
+125
+53
+45
+141
+14
+67
+69
+60
+114
+57
+142
+150
+42
+78
+132
+66
+88
+140
+139
+106
+38
+85
+37
+51
+94
+98
+86
+68
+