Finish 2015.

This commit is contained in:
2024-05-08 18:29:48 -04:00
parent f0a6214052
commit 4e6a44f67b
5 changed files with 134 additions and 29 deletions

40
2015/d23.py Normal file
View File

@@ -0,0 +1,40 @@
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"])