Quantum computing basics · Lesson 2 of 3
Quantum computing basics · Lesson 2 of 3
Quantum programs are built from gates. A one-qubit gate is a 2×2 table of numbers (a matrix). Applying it to the state [a, b] gives a new state:
[g00·a + g01·b, g10·a + g11·b]
The X gate [[0, 1], [1, 0]] swaps the amplitudes: it flips 0 and 1, like a classical NOT. The Hadamard gate H = [[s, s], [s, -s]] with s = 1/√2 turns [1, 0] into an equal superposition. Applying H twice brings the qubit back where it started: the two paths to 1 cancel out. That cancellation, called interference, is what quantum algorithms use.
Write apply(gate, state), which returns the new state after applying a 2×2 gate to [a, b].
All checks pass. Well done.
Next lesson: Measurement and shotsAn AI tutor that gives hints, not answers. It sees your code, its output and this lesson. It can be wrong.