aboutsummaryrefslogtreecommitdiff
path: root/2020/14
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/14
parente257eb53359927c537d2e9c31ca8eae7a0f6dfe7 (diff)
Set file encoding when reading
Diffstat (limited to '2020/14')
-rwxr-xr-x2020/14/puzzle-1.py14
-rwxr-xr-x2020/14/puzzle-2.py22
2 files changed, 18 insertions, 18 deletions
diff --git a/2020/14/puzzle-1.py b/2020/14/puzzle-1.py
index f102316..81f9136 100755
--- a/2020/14/puzzle-1.py
+++ b/2020/14/puzzle-1.py
@@ -18,19 +18,19 @@ def bitmask(mask: str, num: int) -> int:
def main() -> None:
- with open("input", "r") as f:
+ with open("input", "r", encoding="utf-8") as f:
lines = f.read().splitlines()
mem: dict[str, int] = {}
mask = ""
for line in lines:
- line = line.split(" ")
- if line[0] == "mask":
- mask = line[2]
- else:
- mem[line[0][4:-1]] = bitmask(mask, int(line[2]))
+ match line.split(" "):
+ case ["mask", _, mask]:
+ mask = mask
+ case [addr, _, val]:
+ mem[addr[4:-1]] = bitmask(mask, int(val))
- print(sum(mem[val] for val in mem))
+ print(sum(mem.values()))
if __name__ == "__main__":
diff --git a/2020/14/puzzle-2.py b/2020/14/puzzle-2.py
index 45fb6ad..726da0a 100755
--- a/2020/14/puzzle-2.py
+++ b/2020/14/puzzle-2.py
@@ -26,22 +26,22 @@ def bitmask(mask: str, num: int) -> tuple[int, ...]:
def main() -> None:
- with open("input", "r") as f:
+ with open("input", "r", encoding="utf-8") as f:
lines = f.read().splitlines()
mem: dict[str, int] = {}
mask = ""
for line in lines:
- line = line.split(" ")
- if line[0] == "mask":
- mask = line[2]
- else:
- address = line[0][4:-1]
- addresses = bitmask(mask, int(address))
- for a in addresses:
- mem[a] = int(line[2])
-
- print(sum(mem[val] for val in mem))
+ match line.split(" "):
+ case ["mask", _, mask]:
+ mask = mask
+ case [addr, _, val]:
+ address = addr[4:-1]
+ addresses = bitmask(mask, int(address))
+ for a in addresses:
+ mem[a] = int(val)
+
+ print(sum(mem.values()))
if __name__ == "__main__":