def main(): computer = Computer(inputs) computer.put(1) print(computer.eval()) computer = Computer(inputs) computer.put(2) print(computer.eval())
def paint(starting): computer = Computer(inputs) pos = 0, 0 panels = {pos: starting} facing = 0 # up, right, down, left while True: if pos in panels: color = panels[pos] else: color = 0 computer.put(color) try: color = computer.eval() except StopIteration: break panels[pos] = color turn = 1 if computer.eval() == 1 else -1 facing += turn facing %= 4 pos = move(pos, facing) return panels
global score, paddle_x, ball_x while True: try: x = cabinet.eval() y = cabinet.eval() tile_id = cabinet.eval() except Empty: break except StopIteration: return False if x == -1 and y == 0: score = tile_id elif tile_id == 3: paddle_x = x elif tile_id == 4: ball_x = x return True def sign(n): if n < 0: return -1 if n > 0: return 1 return 0 while consume(computer): computer.put(sign(ball_x - paddle_x)) print(score)
#!/usr/bin/env python3 from intcode import Computer with open("inputs/5") as f: inputs = list(map(int, f.readline().strip().split(","))) computer = Computer(inputs) computer.put(1) out = computer.eval() while out == 0: out = computer.eval() print(out) computer = Computer(inputs) computer.put(5) print(computer.eval())