return (int(vector[0] * cos(degrees) - vector[1] * sin(degrees)), int(vector[0] * sin(degrees) + vector[1] * cos(degrees))) hull = defaultdict(lambda: 0) robotpos = (0, 0) robotdirection = (0, 1) computer = IntCode(stdin.read().split(',')) result = computer.run() state = 'painting' while not computer.is_finished: if result is StopIteration: colour = hull[robotpos] computer.send(colour) else: if state == 'painting': hull[robotpos] = result state = 'turning' elif state == 'turning': DIRECTIONS = ('left', 'right') robotdirection = rotate(robotdirection, DIRECTIONS[result]) robotpos = (robotpos[0] + robotdirection[0], robotpos[1] + robotdirection[1]) state = 'painting' else: raise ValueError('bad state')
with open('input') as program: computer = IntCode(program.read().split(',')) computer.memory[0] = 2 screen = Screen(autosolve=True) value = [] while not computer.is_finished: if len(value) == 3: screen.add_sprite(*value) value = [] screen.draw() out = computer.run() if out is StopIteration: while True: char = screen.read_input().lower() try: joystick = {'s': 0, 'a': -1, 'd': 1}[char] break except KeyError: pass computer.send(joystick) else: value.append(out) curses.endwin() print(screen.score)