mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Move 2015 out of the way.
This commit is contained in:
49
2015/day-23/input.txt
Normal file
49
2015/day-23/input.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
jio a, +19
|
||||
inc a
|
||||
tpl a
|
||||
inc a
|
||||
tpl a
|
||||
inc a
|
||||
tpl a
|
||||
tpl a
|
||||
inc a
|
||||
inc a
|
||||
tpl a
|
||||
tpl a
|
||||
inc a
|
||||
inc a
|
||||
tpl a
|
||||
inc a
|
||||
inc a
|
||||
tpl a
|
||||
jmp +23
|
||||
tpl a
|
||||
tpl a
|
||||
inc a
|
||||
inc a
|
||||
tpl a
|
||||
inc a
|
||||
inc a
|
||||
tpl a
|
||||
inc a
|
||||
tpl a
|
||||
inc a
|
||||
tpl a
|
||||
inc a
|
||||
tpl a
|
||||
inc a
|
||||
inc a
|
||||
tpl a
|
||||
inc a
|
||||
inc a
|
||||
tpl a
|
||||
tpl a
|
||||
inc a
|
||||
jio a, +8
|
||||
inc b
|
||||
jie a, +4
|
||||
tpl a
|
||||
inc a
|
||||
jmp +2
|
||||
hlf a
|
||||
jmp -7
|
||||
44
2015/day-23/solution.py
Normal file
44
2015/day-23/solution.py
Normal 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'])
|
||||
|
||||
Reference in New Issue
Block a user