Solve a couple of 2017 problems.
This commit is contained in:
28
2017/d8.py
Normal file
28
2017/d8.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def part_1(data):
|
||||
regs = defaultdict(int)
|
||||
allmax = 0
|
||||
for line in data.splitlines():
|
||||
match line.split():
|
||||
case [reg_a, op, value, "if", reg_c, cmp, val_c]:
|
||||
value, val_c = int(value), int(val_c)
|
||||
reg_val = regs[reg_c]
|
||||
if eval(f"{reg_val} {cmp} {val_c}"):
|
||||
value = value if op == "inc" else -value
|
||||
regs[reg_a] += value
|
||||
case _:
|
||||
assert False
|
||||
allmax = max(max(regs.values()), allmax)
|
||||
print(max(regs.values()))
|
||||
print(allmax)
|
||||
|
||||
|
||||
def main():
|
||||
data = open(0).read().strip()
|
||||
part_1(data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user