My Advent of Code solutions in Python.
kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code
python
1import fileinput
2from intcode import emulate
3
4TAPE = [int(x) for x in fileinput.input()[0].split(',')]
5
6walking = """\
7OR D J
8NOT C T
9AND T J
10NOT A T
11OR T J
12WALK
13"""
14
15running = """\
16NOT C T
17OR T J
18NOT A T
19OR T J
20NOT B T
21OR T J
22AND D J
23AND H J
24NOT A T
25OR T J
26RUN
27"""
28
29for instructions in (walking, running):
30 program = [ord(c) for c in instructions]
31 vm = emulate(TAPE, program[::-1])
32 try:
33 while True:
34 resp = next(vm)
35 chr(resp),
36 except Exception as e:
37 print "{} hull damage: {}".format(instructions.split()[-1], resp)