-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday08.py
More file actions
23 lines (17 loc) · 705 Bytes
/
day08.py
File metadata and controls
23 lines (17 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
registers = dict()
maxes = list()
for i in open("day08.txt").read().split("\n"):
reg, regfunc, regamount, _, comparereg, compareregsign, compareregamount = i.split(" ")
compareregamount = int(compareregamount)
regamount = int(regamount)
registers.setdefault(comparereg, 0)
registers.setdefault(reg, 0)
func = lambda x, a: x+a if regfunc == "inc" else x - a
e = str(registers[comparereg]) + compareregsign + str(compareregamount)
if eval(e):
registers[reg] = func(registers[reg], regamount)
maxes.append(max(registers[key] for key in registers))
# part 1
print("part 1:", max(registers[key] for key in registers))
# part 2
print("part 2:", max(maxes))