コード例 #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
コード例 #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)
コード例 #3
0
 def apply(self, state: State):
     [source] = self.params(state)
     state.add_output(state.program[source])
     super().apply(state)
コード例 #4
0
ファイル: add.py プロジェクト: autoreleasefool/advent-of-code
 def apply(self, state: State):
     [op1, op2, dest] = self.params(state)
     state.program[dest] = op1 + op2
     super().apply(state)
コード例 #5
0
 def apply(self, state: State):
     [comparator, dest] = self.params(state)
     if comparator != 0:
         state.pointer = dest
     else:
         super().apply(state)
コード例 #6
0
 def apply(self, state: State):
     [dest] = self.params(state)
     state.program[dest] = state.next_input
     super().apply(state)