def __init__(self, data: Data, debug=False): self.state = State(program=defaultdict(int)) self.debug = debug for i, n in enumerate(data.nums()): self.state.program[i] = n for op in POSSIBLE_OPS: op.DEBUG = debug Op.DEBUG = debug
def apply(self, state: State): [op1, op2, dest] = self.params(state) state.program[dest] = 1 if op1 < op2 else 0 super().apply(state)
def apply(self, state: State): [source] = self.params(state) state.add_output(state.program[source]) super().apply(state)
def apply(self, state: State): [op1, op2, dest] = self.params(state) state.program[dest] = op1 + op2 super().apply(state)
def apply(self, state: State): [comparator, dest] = self.params(state) if comparator != 0: state.pointer = dest else: super().apply(state)
def apply(self, state: State): [dest] = self.params(state) state.program[dest] = state.next_input super().apply(state)