41 lines
898 B
Python
41 lines
898 B
Python
|
|
insts = []
|
|
with open("i23.txt", "r") as f:
|
|
for line in f:
|
|
args = line.strip().replace(",", "").split()
|
|
insts.append(args)
|
|
|
|
part_2 = True
|
|
i = 0
|
|
regs = {"a": 0, "b": 0}
|
|
if part_2:
|
|
regs["a"] = 1
|
|
|
|
while i < len(insts):
|
|
inst = insts[i]
|
|
match inst:
|
|
case ["inc", reg]:
|
|
regs[reg] += 1
|
|
case ["hlf", reg]:
|
|
regs[reg] //= 2
|
|
case ["tpl", reg]:
|
|
regs[reg] *= 3
|
|
case ["jio", reg, offset]:
|
|
if regs[reg] == 1:
|
|
i += int(offset)
|
|
continue
|
|
case ["jie", reg, offset]:
|
|
offset = int(offset)
|
|
if regs[reg] % 2 == 0:
|
|
i += int(offset)
|
|
continue
|
|
case ["jmp", offset]:
|
|
i += int(offset)
|
|
continue
|
|
case _:
|
|
print(inst)
|
|
assert False
|
|
i += 1
|
|
|
|
print(regs["b"])
|