Finish 2015.
This commit is contained in:
40
2015/d23.py
Normal file
40
2015/d23.py
Normal 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"])
|
||||
Reference in New Issue
Block a user