% Grover search algorithm example for Quack! % by Peter Rohde quack % Prepare the input state init_state(3); prepare_one(3); % Apply Hadamard transform H(1) H(2) H(3) % Apply the oracle n = input('Which of the four basis states should be tagged by the oracle? '); if n == 1 X(1) X(2) toffoli(1,2,3) X(1) X(2) end if n == 2 X(2) toffoli(1,2,3) X(2) end if n == 3 X(1) toffoli(1,2,3) X(1) end if n == 4 toffoli(1,2,3) end % Apply Hadamard transform H(1) H(2) % Apply conditional phase shift X(1) X(2) H(2) cnot(1,2) H(2) X(1) X(2) % Apply Hadamard transform H(1) H(2) H(3) % Measure the output state disp('Measurement outcomes: ') disp(Z_measure(1)) disp(Z_measure(2))