def test_return_correct_result(self): self.assertEqual( process_data('123 -> x'), [(None, None, '123', 'x')] ) self.assertEqual( process_data('x AND y -> z'), [('x', 'AND', 'y', 'z')] ) self.assertEqual( process_data('p LSHIFT 2 -> q'), [('p', 'LSHIFT', '2', 'q')] ) self.assertEqual( process_data('NOT e -> f'), [(None, 'NOT', 'e', 'f')] )
def solve(task): """Recursively process task data to compute wire 'a' value after wire 'b' signal overriding Args: task: "NOT dq -> dr\nkg OR kf -> kh..." Returns: int: wire 'a' signal value """ commands = process_data(task) wires = HDict() for command in commands: wires[command.output] = command wires['b'] = get_value(wires['a'], wires) return get_value(wires['a'], wires)