From be00c038400b7bb6e00662658ed80f2e1663a271 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Mon, 4 Apr 2022 21:36:06 +0200 Subject: [PATCH] [WIP] Solution to problem 8 part 1 in Python --- src/Year_2017/P8.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/Year_2017/P8.py diff --git a/src/Year_2017/P8.py b/src/Year_2017/P8.py new file mode 100644 index 0000000..4ddf353 --- /dev/null +++ b/src/Year_2017/P8.py @@ -0,0 +1,21 @@ +from collections import defaultdict + +with open("files/P8.txt") as f: + instructions = [line for line in f.read().strip().split("\n")] + +# print(instructions) + +registry: dict[str, int] = defaultdict(int) + + +def inc(s: str) -> None: + reg, inst, num, iff, reg_cond, op, num_cond = s.split() + if eval("registry[reg_cond] " + op + num_cond): + registry[reg] += int(num) + + +for instruction in instructions: + inc(instruction) + break + +print(registry)