from qiskit import QuantumCircuit
from qiskit.visualization import plot_histogram
qc=QuantumCircuit(4,2) ## for adder we need four quantum register and 2 classical register

qc.barrier()
# use cnots to write the XOR of the inputs on qubit 2
qc.cx(0,2)
qc.cx(1,2)
qc.ccx(0,1,3)
qc.barrier()
# extract outputs
qc.measure(2,0) # extract XOR value
qc.measure(3,1)

qc.draw()

from qiskit import Aer
sim = Aer.get_backend('aer_simulator') 
from qiskit import assemble     
qobj = assemble(qc)
counts = sim.run(qobj).result().get_counts()
plot_histogram(counts)

from qiskit import QuantumCircuit
qc1=QuantumCircuit(4,2) ## for adder we need four quantum register and 2 classical register

qc1.x(1)
qc1.barrier()
# use cnots to write the XOR of the inputs on qubit 2
qc1.cx(0,2)
qc1.cx(1,2)
qc1.ccx(0,1,3)
qc1.barrier()
# extract outputs
qc1.measure(2,0) # extract XOR value
qc1.measure(3,1)

qc1.draw()

from qiskit import Aer
sim = Aer.get_backend('aer_simulator') 
from qiskit import assemble     
qobj = assemble(qc1)
counts = sim.run(qobj).result().get_counts()
plot_histogram(counts)

from qiskit import QuantumCircuit
qc2=QuantumCircuit(4,2) ## for adder we need four quantum register and 2 classical register

qc2.x(0)
qc2.barrier()
# use cnots to write the XOR of the inputs on qubit 2
qc2.cx(0,2)
qc2.cx(1,2)
qc2.ccx(0,1,3)
qc2.barrier()
# extract outputs
qc2.measure(2,0) # extract XOR value
qc2.measure(3,1)

qc2.draw()

from qiskit import Aer
sim = Aer.get_backend('aer_simulator') 
from qiskit import assemble     
qobj = assemble(qc2)
counts = sim.run(qobj).result().get_counts()
plot_histogram(counts)

from qiskit import QuantumCircuit
qc3=QuantumCircuit(4,2) ## for adder we need four quantum register and 2 classical register

qc3.x(0)
qc3.x(1)
qc3.barrier()
# use cnots to write the XOR of the inputs on qubit 2
qc3.cx(0,2)
qc3.cx(1,2)
qc3.ccx(0,1,3)
qc3.barrier()
# extract outputs
qc3.measure(2,0) # extract XOR value
qc3.measure(3,1)

qc3.draw()

from qiskit import Aer
sim = Aer.get_backend('aer_simulator') 
from qiskit import assemble     
qobj = assemble(qc3)
counts = sim.run(qobj).result().get_counts()
plot_histogram(counts)

