aboutsummaryrefslogtreecommitdiff
path: root/2020/10/puzzle-2.py
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-12-02 13:58:27 +0100
committerThomas Voss <thomasvoss@live.com> 2021-12-02 13:58:27 +0100
commit3ac99f409ae6545e2f4fece4d9397d28d35b279b (patch)
tree5757e252e197e97d6f64f5485a07a8c83739e20c /2020/10/puzzle-2.py
parente257eb53359927c537d2e9c31ca8eae7a0f6dfe7 (diff)
Set file encoding when reading
Diffstat (limited to '2020/10/puzzle-2.py')
-rwxr-xr-x2020/10/puzzle-2.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/2020/10/puzzle-2.py b/2020/10/puzzle-2.py
index bdf7bbf..3042a2b 100755
--- a/2020/10/puzzle-2.py
+++ b/2020/10/puzzle-2.py
@@ -1,7 +1,5 @@
#!/usr/bin/env python3
-from typing import List
-
adaptors: list[str]
@@ -11,18 +9,16 @@ def combos(i: int, counts: dict[int, dict[int, int]] = {}) -> int:
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
+ counts[i] = sum(
+ combos(j, counts) if adaptors[j] - adaptors[i] <= 3 else 0
+ for j in range(i + 1, len(adaptors))
+ )
+ return counts[i]
def main() -> None:
global adaptors
- with open("input", "r") as f:
+ with open("input", "r", encoding="utf-8") as f:
adaptors = list(map(int, f.readlines()))
adaptors.append(0)