diff options
Diffstat (limited to '2020/14/puzzle-1.py')
-rwxr-xr-x | 2020/14/puzzle-1.py | 14 |
1 files changed, 7 insertions, 7 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__": |