···11+import fileinput
22+33+44+def simulate(program, a=0, b=0, c=0, d=0):
55+ pc = 0
66+ regs = {'a': a, 'b': b, 'c': c, 'd': d}
77+88+ while True:
99+ if pc >= len(program):
1010+ return regs
1111+1212+ inst = program[pc].split()
1313+1414+ if len(inst) == 2:
1515+ cmd, x = inst
1616+ y = None
1717+ else:
1818+ cmd, x, y = inst
1919+2020+ if cmd == 'cpy':
2121+ regs[y] = int(x) if x.isdigit() else regs[x]
2222+2323+ elif cmd == 'inc':
2424+ regs[x] += 1
2525+2626+ elif cmd == 'dec':
2727+ regs[x] -= 1
2828+2929+ elif cmd == 'jnz':
3030+ x = int(x) if x.isdigit() else regs[x]
3131+3232+ if x == 0:
3333+ pc += 1
3434+ continue
3535+ else:
3636+ pc += int(y)
3737+ continue
3838+3939+ pc += 1
4040+4141+4242+PROGRAM = [line.strip() for line in fileinput.input()]
4343+4444+print "Value in register a:", simulate(PROGRAM)['a']
4545+print "When setting c to 1:", simulate(PROGRAM, c=1)['a']
+23
2016/input12.txt
···11+cpy 1 a
22+cpy 1 b
33+cpy 26 d
44+jnz c 2
55+jnz 1 5
66+cpy 7 c
77+inc d
88+dec c
99+jnz c -2
1010+cpy a c
1111+inc a
1212+dec b
1313+jnz b -2
1414+cpy c b
1515+dec d
1616+jnz d -6
1717+cpy 19 c
1818+cpy 11 d
1919+inc a
2020+dec d
2121+jnz d -2
2222+dec c
2323+jnz c -5