from qiskit import IBMQ, BasicAer
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
qr = QuantumRegister(3) # Initialize qubits
cr = ClassicalRegister(3) # Initialize bits for record measurements
circuit = QuantumCircuit(qr, cr)
# We want to search two marked states
# |101> and |110>
# Apply Hadamard to all qubits
circuit.h(qr)
circuit.barrier()
# Phase oracle (Marks states |101> and |110> as results)
circuit.cz(qr[2], qr[0])
circuit.cz(qr[2], qr[1])
# Inversion around the average
circuit.h(qr)
circuit.x(qr)
circuit.barrier()
circuit.h(qr[2])
circuit.ccx(qr[0], qr[1], qr[2])
circuit.h(qr[2])
circuit.barrier()
circuit.x(qr)
circuit.h(qr)
# Measure
circuit.measure(qr, cr)
# Run our circuit with local simulator
backend = BasicAer.get_backend('qasm_simulator')
shots = 1024
results = execute(circuit, backend=backend, shots=shots).result()
answer = results.get_counts()
print(answer)