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/09 | |
parent | e257eb53359927c537d2e9c31ca8eae7a0f6dfe7 (diff) |
Set file encoding when reading
Diffstat (limited to '2020/09')
-rwxr-xr-x | 2020/09/puzzle-1.py | 11 | ||||
-rwxr-xr-x | 2020/09/puzzle-2.py | 3 |
2 files changed, 5 insertions, 9 deletions
diff --git a/2020/09/puzzle-1.py b/2020/09/puzzle-1.py index f68fc21..7676f2d 100755 --- a/2020/09/puzzle-1.py +++ b/2020/09/puzzle-1.py @@ -1,17 +1,12 @@ #!/usr/bin/env python3 -from typing import List -def is_valid(nums: List[int], lp: int, up: int) -> bool: - for i in range(lp, up): - x = nums[up] - nums[i] - if x in nums[lp:up] and x != nums[i]: - return True - return False +def is_valid(nums: list[int], lp: int, up: int) -> bool: + return any(((x := nums[up] - nums[i]) in nums[lp:up] and x != nums[i]) for i in range(lp, up)) def main() -> None: - with open("input", "r") as f: + with open("input", "r", encoding="utf-8") as f: nums = list(map(int, f.readlines())) lp = 0 diff --git a/2020/09/puzzle-2.py b/2020/09/puzzle-2.py index 8833f50..c890fb3 100755 --- a/2020/09/puzzle-2.py +++ b/2020/09/puzzle-2.py @@ -1,10 +1,11 @@ #!/usr/bin/env python3 + import numpy as np def main() -> None: goal = 138879426 - with open("input", "r") as f: + with open("input", "r", encoding="utf-8") as f: nums = np.array(list(map(int, f.readlines())), dtype=int) lp = 0 |