Editorial
The oracle takes single qubit computational basis states and and outputs . Its truth table is as follows:
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 1 | 0 |
From the truth table, the bit flips only when . Such an operation can be achieved by using a controlled- gate 1, with as the control qubit and as the target qubit.
Thus, the problem can be solved using the controlled- gate.
Sample Code
Below is a sample program:
from qiskit import QuantumCircuit, QuantumRegister
def solve() -> QuantumCircuit:
x, y = QuantumRegister(1), QuantumRegister(1)
qc = QuantumCircuit(x, y)
qc.cx(x, y)
return qcFootnotes
-
For more information about controlled gates, please refer to the editorial of problem A3. ↩