def calc_thrust(inlist, program): A = IntCode(program, in_vals=[inlist[0], 0]) B = IntCode(program, in_vals=[inlist[1]]) C = IntCode(program, in_vals=[inlist[2]]) D = IntCode(program, in_vals=[inlist[3]]) E = IntCode(program, in_vals=[inlist[4]]) A.run() B.input = [inlist[1], A.output] B.run() C.input = [inlist[2], B.output] C.run() D.input = [inlist[3], C.output] D.run() E.input = [inlist[4], D.output] E.run() A.input = [inlist[0], E.output] while not E.stopped: A.run() B.input = [A.output] B.run() C.input = [B.output] C.run() D.input = [C.output] D.run() E.input = [D.output] E.run() A.input = [E.output] return E.output
def run(part): robot = IntCode([int(i) for i in open("../input/11.txt").read().split(",")]) hull = [[0 for _ in range(80)] for _ in range(80)] coords = (20, 20) direction = Direction.UP painted = set() if part == 2: hull[coords[1]][coords[0]] = 1 while True: robot.input(hull[coords[1]][coords[0]]) out = robot.run() if out is None: break painted.add(coords) hull[coords[1]][coords[0]] = out direction = turn[robot.run()](direction) coords = move[direction](*coords) if part == 1: return len(painted) else: return '\n'.join([''.join( [[' ', '#'][panel] for panel in row]) for row in hull[::-1] if 1 in row])
def run_test(prog, system_id): """ Inputs a system id to the IntCode VM, and then runs it until it outputs a non-zero code (and returns the code) """ vm = IntCode(input) vm.input(system_id) while True: code = vm.output() if code != 0: return code