From 3ac99f409ae6545e2f4fece4d9397d28d35b279b Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Thu, 2 Dec 2021 13:58:27 +0100 Subject: Set file encoding when reading --- 2020/10/puzzle-2.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to '2020/10/puzzle-2.py') 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) -- cgit v1.2.3