def part2(pc: intcode.Computer) -> int: pc.reset(wait_for_input=True) pc.data[0] = 2 # initial setup pc.run() idx = pc.output.index(-1) while pc.output[idx + 1] != 0: idx = pc.output.index(-1, idx + 1) entities = getEntities(pc.output[:idx]) pc.output = pc.output[idx:] # loop while not pc.stop: pc.run() changes = getEntities(pc.output) if changes["score"]: entities["score"] = changes["score"] if changes["ball"]: changes["empty"].remove(entities["ball"]) entities["ball"] = changes["ball"] if changes["paddle"]: changes["empty"].remove(entities["paddle"]) entities["paddle"] = changes["paddle"] for e in changes["empty"]: entities["block"].remove(e) pc.output.clear() pc.input = entities["ball"][0] - entities["paddle"][0] return entities["score"]
def part2(pc: intcode.Computer) -> int: for noun in range(100): for verb in range(100): pc.reset() pc.data[1], pc.data[2] = noun, verb pc.run() if pc.data[0] == 19690720: return 100 * noun + verb
class CheckPoint: def __init__(self, source): self.prog = [int(c) for c in source.split(',')] self.comp = Computer(self.prog) def __call__(self, inp): self.comp.reset(self.prog) self.comp.run(inp) return self.comp.output[0]
def part2(input): """ >>> import aoc_input as inp; part2(inp.read(2)) 6635 """ ic = Computer(input) target_val = 19690720 for noun in range(99): for verb in range(99): ic.reset() ic.seq[1] = noun ic.seq[2] = verb ic.run() if ic.seq[0] == target_val: break if ic.seq[0] == target_val: break return 100 * noun + verb
def part2(pc: intcode.Computer) -> int: pc.reset(input=2) pc.run() return pc.data[0]