From 3ac99f409ae6545e2f4fece4d9397d28d35b279b Mon Sep 17 00:00:00 2001 From: Thomas Voss <thomasvoss@live.com> Date: Thu, 2 Dec 2021 13:58:27 +0100 Subject: Set file encoding when reading --- 2020/16/puzzle-1.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to '2020/16/puzzle-1.py') diff --git a/2020/16/puzzle-1.py b/2020/16/puzzle-1.py index f4343c8..9f35856 100755 --- a/2020/16/puzzle-1.py +++ b/2020/16/puzzle-1.py @@ -2,7 +2,7 @@ def main() -> None: - with open("input", "r") as f: + with open("input", "r", encoding="utf-8") as f: data = f.readlines() i = 0 @@ -11,8 +11,7 @@ def main() -> None: ranges = data[i].split(": ")[1].split(" or ") for _range in ranges: bounds = tuple(map(int, _range.split("-"))) - for j in range(bounds[0], bounds[1] + 1): - valid.append(j) + valid.extend(range(bounds[0], bounds[1] + 1)) i += 1 # Skip to nearby tickets @@ -20,8 +19,7 @@ def main() -> None: acc = 0 for j in range(i, len(data)): - fields = tuple(map(int, data[j].split(","))) - acc += sum(field for field in fields if field not in valid) + acc += sum(field for field in tuple(map(int, data[j].split(","))) if field not in valid) print(acc) -- cgit v1.2.3