def part1(): program = get_input() vm, screen = IntcodeVm(program, []), {} while True: try: a, b, c = vm.receive(), vm.receive(), vm.receive() screen[(a, b)] = c except StopIteration: break return sum(v == 2 for v in screen.values())
def paint(prog, initial_white_tiles = []): vm = IntcodeVm(prog) visited, whites, pos, direction = set(), set(initial_white_tiles), (0, 0), 'U' while True: vm.send(1 if pos in whites else 0) try: paint, lr = vm.receive(), vm.receive() visited.add(pos) if paint == 1: whites.add(pos) elif paint == 0: whites.discard(pos) direction = turn(direction, lr) pos = move(pos, direction) except StopIteration: break return visited, whites
def is_beam(x, y): vm = IntcodeVm(PROGRAM) vm.send(x) vm.send(y) return vm.receive() == 1