My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2019/21

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