Codercise I.13.5

# Wires 0, 1, 2 are the control qubits
# Wire 3 is the auxiliary qubit
# Wire 4 is the target
dev = qml.device("default.qubit", wires=5)


@qml.qnode(dev)
def four_qubit_mcx_only_tofs():
    # We will initialize the control qubits in state |1> so you can see
    # how the output state gets changed.
    qml.PauliX(wires=0)
    qml.PauliX(wires=1)
    qml.PauliX(wires=2)

    ##################
    # YOUR CODE HERE #
    ##################

    # IMPLEMENT A 3-CONTROLLED NOT WITH TOFFOLIS

    qml.Toffoli(wires=[0, 1, 3])
    qml.Toffoli(wires=[3, 2, 4])
    qml.Toffoli(wires=[0, 1, 3])
    return qml.state()


print(four_qubit_mcx_only_tofs())

Can’t figure out what’s going wrong here. It keeps giving me this error- Error: Your gates are not applied to the correct wires.

It works when I changed the second Toffoli to [2,3,4].

Hi @pavitraallamaraju ,

Welcome to the Forum!

It’s great to see that you solved the codercise. I’ve blurred your answer to avoid spoilers for others.

I hope you keep enjoying the Codebook!