aboutsummaryrefslogtreecommitdiff
path: root/2020/10
diff options
context:
space:
mode:
Diffstat (limited to '2020/10')
-rw-r--r--2020/10/input108
-rwxr-xr-x2020/10/puzzle-1.sh7
-rwxr-xr-x2020/10/puzzle-2.py36
3 files changed, 151 insertions, 0 deletions
diff --git a/2020/10/input b/2020/10/input
new file mode 100644
index 0000000..379b145
--- /dev/null
+++ b/2020/10/input
@@ -0,0 +1,108 @@
+147
+174
+118
+103
+67
+33
+96
+28
+43
+22
+16
+138
+75
+148
+35
+6
+10
+169
+129
+115
+21
+52
+58
+79
+46
+7
+139
+104
+91
+51
+172
+57
+49
+126
+95
+149
+125
+123
+112
+30
+78
+44
+37
+167
+157
+29
+173
+98
+36
+63
+111
+160
+18
+8
+9
+159
+179
+72
+110
+2
+53
+150
+17
+81
+97
+108
+102
+56
+135
+166
+168
+163
+1
+25
+3
+158
+101
+132
+144
+45
+140
+34
+156
+178
+105
+68
+153
+80
+82
+59
+50
+122
+69
+85
+109
+40
+124
+119
+94
+88
+13
+180
+177
+133
+66
+134
+60
+141
diff --git a/2020/10/puzzle-1.sh b/2020/10/puzzle-1.sh
new file mode 100755
index 0000000..f31af02
--- /dev/null
+++ b/2020/10/puzzle-1.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env sh
+
+sort -n input | awk '
+BEGIN { o = t = 1 }
+NR > 1 { if ($0 - prev == 1) o++; else if ($0 - prev == 3) t++; }
+ { prev = $0 }
+END { print o * t }'
diff --git a/2020/10/puzzle-2.py b/2020/10/puzzle-2.py
new file mode 100755
index 0000000..bdf7bbf
--- /dev/null
+++ b/2020/10/puzzle-2.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+
+from typing import List
+
+adaptors: list[str]
+
+
+def combos(i: int, counts: dict[int, dict[int, int]] = {}) -> int:
+ if i == len(adaptors) - 1:
+ return 1
+ if i in counts:
+ return counts[i]
+
+ ans = 0
+ for j in range(i + 1, len(adaptors)):
+ if adaptors[j] - adaptors[i] <= 3:
+ ans += combos(j, counts)
+
+ counts[i] = ans
+ return ans
+
+
+def main() -> None:
+ global adaptors
+ with open("input", "r") as f:
+ adaptors = list(map(int, f.readlines()))
+
+ adaptors.append(0)
+ adaptors.sort()
+ adaptors.append(max(adaptors) + 3)
+
+ print(combos(0))
+
+
+if __name__ == "__main__":
+ main()