import qiskit
%matplotlib inline
qiskit.__qiskit_version__

len = 4
q_r = qiskit.QuantumRegister(len, 'q')
c_r = qiskit.ClassicalRegister(len, 'c')
q_c = qiskit.QuantumCircuit(q_r, c_r)

q_c.h([q_r[0],q_r[3]])
q_c.x([q_r[0],q_r[3]])
q_c.ccx(q_r[0],q_r[3],q_r[1])
q_c.x([q_r[0],q_r[3]])
q_c.ccx(q_r[0],q_r[3],q_r[2])
q_c.cx(q_r[2],q_r[0])
q_c.cx(q_r[2],q_r[3])


#q_c.barrier()
q_c.measure(q_r,c_r)
q_c.draw(output='latex', line_length=300, scale=0.5)   




sim = qiskit.BasicAer.get_backend('qasm_simulator')
job = qiskit.execute(q_c, backend = sim, shots = 1000)
res = job.result().get_counts()
print(res)
qiskit.visualization.plot_histogram(res)

print(q_c.qasm())

