def first(): values = [ 109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 ] computer = Computer.IntCode(values, extend=True, auto=True) print(f"(test) {computer.output()}") values = [1102, 34915192, 34915192, 7, 4, 7, 99, 0] computer = Computer.IntCode(values, extend=True, auto=True) print(f"(test) {computer.output()[0]}") values = DataAnalyzer.int_csv("2019day9.txt")[0] computer = Computer.IntCode(values, [1], extend=True, auto=True) print(f"(9.1) {computer.output()[0]}")
def amplifier(values, phase, thrusters, signal, amplify): complete = 1 active = None inputs = [signal] output = [0 for _ in range(len(phase))] computers = [Computer.IntCode(values.copy(), phase[i], interrupt=amplify) for i in range(len(phase))] while complete <= len(phase): active = 0 if active is None else thrusters[active] cpu = computers[active] # cpu.debug(True) if not cpu.done: if len(inputs) > 0: computers[active].inputs(inputs.pop(0)) cpu.start() data = cpu.output() if len(data) > 0: output[active] = data[0] inputs.append(data[0]) if cpu.done: complete += 1 return output
def second(): def detection(x, y): if x > n and y > n: return True if radar[x - n][y - n:y].count(1) == n and [ m[y - n] for m in radar[x - n:x] ].count(1) == n else False else: return False values = DataAnalyzer.int_csv("2019day19.txt")[0] cpu = Computer.IntCode(values, extend=True, interrupt=False, auto=False, x=25000) done, i, j, size, n = False, 0, 0, 1700, 100 radar = [[0 for i in range(size)] for j in range(size)] for i in range(size): for j in range(size): cpu.reset([i, j]) cpu.start() radar[i][j] = cpu.output()[0] done = detection(i + 1, j + 1) if done: break if done: break print( f"(19.2) LOCATED: {done}, {n}x{n} block at {i-n+1},{j-n+1} :: ship math = {(i-n+1)*10000 + j-n+1}" )
def first(): values = DataAnalyzer.int_csv("2019day13.txt")[0] computer = Computer.IntCode(values, extend=True, auto=True) count = 0 output = computer.output() for i in range(0, len(output), 3): count += 1 if output[i+2] == 2 else 0 print(f"(13.1) Block tile count: {count}")
def first(): values = DataAnalyzer.int_csv("2019day19.txt")[0] count = 0 cpu = Computer.IntCode(values, extend=True, interrupt=False, auto=False) for i in range(50): for j in range(50): cpu.reset([i, j]) cpu.start() count += 1 if cpu.output()[0] == 1 else 0 print(f"(19.1) affected points: {count}")
def play(values, debug=False): ball = paddle = None point = 0 def inputter(): return (ball > paddle) - (ball < paddle) values[0] = 2 computer = Computer.IntCode(values, input_func=inputter, extend=True, interrupt=True) computer.debug(debug) while not computer.done: computer.start() computer.start() computer.start() blocks = computer.output(3) if not computer.done: paddle = blocks[0] if blocks[2] == 3 else paddle ball = blocks[0] if blocks[2] == 4 else ball point = blocks[2] if (blocks[0], blocks[1]) == (-1, 0) else point return point
def second(): values = DataAnalyzer.int_csv("2019day9.txt")[0] computer = Computer.IntCode(values, [2], extend=True, auto=True) print(f"(9.2) {computer.output()[0]}")
def second(): values = DataAnalyzer.int_csv("2019day5.txt")[0] computer = Computer.IntCode(values, [5], auto=True) print(f"(5.2) {computer.output()[0]}")
def first(): values = DataAnalyzer.int_csv("2019day5.txt")[0] computer = Computer.IntCode(values, [1], auto=True) print(f"(5.1) {computer.output()}")