diff options
author | Thomas Voss <thomasvoss@live.com> | 2021-12-02 13:58:27 +0100 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2021-12-02 13:58:27 +0100 |
commit | 3ac99f409ae6545e2f4fece4d9397d28d35b279b (patch) | |
tree | 5757e252e197e97d6f64f5485a07a8c83739e20c /2020/16/puzzle-1.py | |
parent | e257eb53359927c537d2e9c31ca8eae7a0f6dfe7 (diff) |
Set file encoding when reading
Diffstat (limited to '2020/16/puzzle-1.py')
-rwxr-xr-x | 2020/16/puzzle-1.py | 8 |
1 files changed, 3 insertions, 5 deletions
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) |