Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
 def apply(self, state: State):
     [op1, op2, dest] = self.params(state)
     state.program[dest] = 1 if op1 < op2 else 0
     super().apply(state)
Ejemplo n.º 3
0
 def apply(self, state: State):
     [source] = self.params(state)
     state.add_output(state.program[source])
     super().apply(state)
Ejemplo n.º 4
0
 def apply(self, state: State):
     [op1, op2, dest] = self.params(state)
     state.program[dest] = op1 + op2
     super().apply(state)
Ejemplo n.º 5
0
 def apply(self, state: State):
     [comparator, dest] = self.params(state)
     if comparator != 0:
         state.pointer = dest
     else:
         super().apply(state)
Ejemplo n.º 6
0
 def apply(self, state: State):
     [dest] = self.params(state)
     state.program[dest] = state.next_input
     super().apply(state)