# Two entangled qubits: a Bell pair. Measure one and you know the other.
from tiny_qsim import Random, H, start, apply, cnot, show, measure, label

state = start(2)
apply(state, H, 0, 2)    # qubit 0 becomes half 0, half 1
cnot(state, 0, 1, 2)     # qubit 1 copies qubit 0
print("After Hadamard on qubit 0 and CNOT from qubit 0 to qubit 1:")
show(state, 2)

counts = measure(state, 1000, Random(2026))
print("Measured 1000 times:")
for i in range(len(counts)):
    print(f"  {label(i, 2)}: {counts[i]}")
print("You only ever see 00 or 11. The two qubits always agree.")
