# Import the Qiskit SDK.
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import available_backends, execute, Aer
from qiskit.tools.visualization import plot_histogram, circuit_drawer, plot_state
# Define the number of n-qbits.
n = 6
# Create a Quantum Register with n-qbits.
q = QuantumRegister(n)
# Create a Classical Register with n-bits.
c = ClassicalRegister(n)
# Create a Quantum Circuit
qc = QuantumCircuit(q, c)

# Init with |1>
qc.x(q[0])
qc.x(q[1])

# Add H-gate to get superposition.
qc.h(q[0])
qc.h(q[1])

# Apply the oracle 11.
qc.cx(q[0],q[1],q[2])

qc.x(q[0])
qc.x(q[1])
qc.cx(q[0],q[1],q[3])
qc.x(q[0])
qc.x(q[1])

qc.x(q[0])
qc.cx(q[0],q[4])
qc.x(q[0])

qc.x(q[2])
qc.x(q[3])
qc.x(q[4])
qc.x(q[5])
qc.cx(q[2],q[3],q[4],q[5])
qc.x(q[2])
qc.x(q[3])
qc.x(q[4])
qc.x(q[5])

qc.z(q[5])

qc.x(q[2])
qc.x(q[3])
qc.x(q[4])
qc.x(q[5])
qc.cx(q[2],q[3],q[4],q[5])
qc.x(q[2])
qc.x(q[3])
qc.x(q[4])
qc.x(q[5])

qc.x(q[0])
qc.cx(q[0],q[4])
qc.x(q[0])

qc.x(q[0])
qc.x(q[1])
qc.cx(q[0],q[1],q[3])
qc.x(q[0])
qc.x(q[1])

qc.cx(q[0],q[1],q[2])

# Apply the grover-algorithm 11


# Measure qubit to bit. .
qc.measure(q, c)

# Get Aer backend.
backend_sim = Aer.get_backend('qasm_simulator')
# Compile and run the Quantum circuit on a simulator backend.
sim_result1 = execute(qc, backend_sim, shots=1000).result()
counts1 = sim_result1.get_counts(qc)
# Show the results as text and plot.
print("Simulation: ", sim_result1)
print("Output: ", counts1)
plot_histogram(counts1)
circuit_drawer(qc)

