Move 2015 out of the way.

This commit is contained in:
Bert Peters
2016-12-01 11:25:19 +01:00
parent a75d14ec17
commit b37fd44fa7
50 changed files with 0 additions and 0 deletions

44
2015/day-23/solution.py Normal file
View File

@@ -0,0 +1,44 @@
from __future__ import division, print_function
import fileinput
import re
def run(instructions, registers):
instrptr = 0
while instrptr < len(instructions):
instruction = instructions[instrptr]
if "j" in instruction[0]:
if instruction[0] == "jie":
doJump = registers[instruction[1]] % 2 == 0
elif instruction[0] == "jio":
doJump = registers[instruction[1]] == 1
else:
doJump = True
if doJump:
instrptr = instrptr + int(instruction[-1])
else:
instrptr += 1
continue
if instruction[0] == "hlf":
registers[instruction[1]] //= 2
elif instruction[0] == "tpl":
registers[instruction[1]] *= 3
else:
registers[instruction[1]] += 1
instrptr += 1
return registers
instructions = []
for line in fileinput.input():
instructions.append(tuple(x.strip() for x in re.match(r"(hlf|tpl|inc|jmp|jie|jio) (a|b)?,? ?(\+?-?[0-9]+)?", line).groups() if x is not None))
print(run(instructions, {'a': 0, 'b': 0})['b'])
print(run(instructions, {'a': 1, 'b': 0})['b'])