def main(): with open("program.txt") as f: program = [int(n) for n in f.read().strip().split(",")] c = int_code_computer(program) print(c.send(1)) c = int_code_computer(program) print(c.send(2))
def main(): with open("program.txt") as f: program = map(int, f.readline().strip().split(",")) c = int_code_computer(program) hull = defaultdict(int) pos = np.array([0, 0]) heading = np.array([-1, 0]) hull[tuple(pos)] = 1 while True: try: hull[tuple(pos)] = c.send(hull[tuple(pos)]) heading = (2 * next(c) - 1) * rot(heading) pos += heading next(c) except StopIteration: break min_i = min(k[0] for k in hull.keys()) max_i = max(k[0] for k in hull.keys()) + 1 min_j = min(k[1] for k in hull.keys()) max_j = max(k[1] for k in hull.keys()) + 1 for i in range(min_i, max_i): for j in range(min_j, max_j): if (i, j) in hull and hull[i, j] == 1: print("#", end="") else: print(" ", end="") print()
def main(): with open("program.txt") as f: program = [int(n) for n in f.readline().strip().split(",")] output_queue = Queue() c = int_code_computer(program, Queue(), output_queue) outputs = iter(output_queue.get, StopIteration) print(sum(tile == 2 for _, _, tile in grouper(3, outputs, fillvalue=None)))
def main(): with open("amplifier_program.txt") as f: amplifier_program = [int(n) for n in f.readline().strip().split(",")] max_signal = 0 for phase_setting in permutations(range(5)): computers = [int_code_computer(amplifier_program) for _ in range(5)] for phase, comp in zip(phase_setting, computers): comp.send(phase) signal = 0 for comp in computers: signal = comp.send(signal) max_signal = max(signal, max_signal) print(max_signal)
def main(): with open("program.txt") as f: program = map(int, f.readline().strip().split(",")) c = int_code_computer(program) hull = defaultdict(int) pos = np.array([0, 0]) heading = np.array([-1, 0]) while True: try: hull[tuple(pos)] = c.send(hull[tuple(pos)]) heading = (2 * next(c) - 1) * rot(heading) pos += heading next(c) except StopIteration: break print(len(hull))