# import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer

# we use four pairs of two qubits in order to see all results at once
# the first pair -> qubits with indices 0 and 1
# the second pair -> qubits with indices 2 and 3
# the third pair -> qubits with indices 4 and 5
# the fourth pair -> qubits with indices 6 and 7
qreg =  QuantumRegister(8)
creg = ClassicalRegister(8)
mycircuit = QuantumCircuit(qreg,creg)

# the first pair is already in |00>

# the second pair is set to be in |01>
mycircuit.x(qreg[3])

# the third pair is set to be in |10>
mycircuit.x(qreg[4])

# the fourth pair is set to be in |11>
mycircuit.x(qreg[6])
mycircuit.x(qreg[7])

# apply cx to each pair
for i in range(0,8,2): # i = 0,2,4,6
    mycircuit.cx(qreg[i],qreg[i+1])

# measure the quantum register
mycircuit.measure(qreg,creg)

print("Everything looks fine, let's continue ...")

# draw the circuit

drawer(mycircuit)
# re-run this cell if you DO NOT see the circuit diagram

# execute the circuit 1000 times in the local simulator

job = execute(mycircuit,Aer.get_backend('qasm_simulator'),shots=1000)
counts = job.result().get_counts(mycircuit)
# print the reverse of the output
for outcome in counts:
    reverse_outcome = ''
    for i in outcome:
        reverse_outcome = i + reverse_outcome
    print(reverse_outcome,"is observed",counts[outcome],"times")
    print()
    print("let's also split into the pairs")
    for i in range(0,8,2):
        print(reverse_outcome[i:i+2])

# import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer
# import randrange for random choices
from random import randrange

#
# your code is here
#


# import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer

#
# your code is here
#


# import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer

#
# your code is here
#
