# Codexercise I.13.5 possible bug

**URL:** <https://discuss.pennylane.ai/t/codexercise-i-13-5-possible-bug/9416>\
**Category:** Codebook\
**Created:** [July 21, 2026, 3:48pm UTC](https://discuss.pennylane.ai/t/codexercise-i-13-5-possible-bug/9416 "2026-07-21T15:48:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anton\_Naumov](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/anton_naumov/32/3519_2.png) [@Anton\_Naumov](https://discuss.pennylane.ai/u/Anton_Naumov)\
**Post date:** [July 21, 2026, 3:48pm UTC](https://discuss.pennylane.ai/t/codexercise-i-13-5-possible-bug/9416/1 "2026-07-21T15:48:37Z")

</div>

Hi,

First of all, thank you for your excellent study materials and codexercises, they really thoughtful and engaging. My issue might be a duplicate of something, if so – sorry for that.

Was recently solving Codexercise I.13.5, tried this solution:

```auto
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.
    qp.PauliX(wires=0)
    qp.PauliX(wires=1)
    qp.PauliX(wires=2)

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

    # IMPLEMENT A 3-CONTROLLED NOT WITH TOFFOLIS
    qp.Toffoli(wires=[1,2,3])
    qp.Toffoli(wires=[0,3,4])
    qp.Toffoli(wires=[1,2,3])
    return qp.state()

```

and the scoring system outputed the following error:

```auto
Error: Your gates are not applied to the correct wires

```

While I have found the correct implementation, the one I’ve shown above seem to provide with the same result. Is this error done intentionally (and if so, what was the intention), or is it a scoring system bug?

PS: I guess this order should work too:

```python
qp.Toffoli(wires=[0,2,3])
qp.Toffoli(wires=[1,3,4])
qp.Toffoli(wires=[0,2,3])

```

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [July 23, 2026, 9:16pm UTC](https://discuss.pennylane.ai/t/codexercise-i-13-5-possible-bug/9416/2 "2026-07-23T21:16:30Z")

</div>

Hi @Anton_Naumov, welcome to the Forum, and thank you for your kind words!

We love hearing that you find the material thoughtful and engaging, and I’ve shared your feedback with our team.

You’ve raised a great question. We are going to look into this and get back to you!

---

<div class="post-metadata">

**Author:** ![gabriela](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@gabriela](https://discuss.pennylane.ai/u/gabriela)\
**Post date:** [July 24, 2026, 10:08pm UTC](https://discuss.pennylane.ai/t/codexercise-i-13-5-possible-bug/9416/3 "2026-07-24T22:08:29Z")

</div>

Hi @Anton_Naumov,  
Thanks for your report and the clear examples! You’re absolutely right, this is a bug on our side, not an error in your solution.

The answers you found are perfectly valid implementations of the 3-controlled-NOT in codercise I.13.5. Indeed there are 3 possible solutions that produce the same final state. For example, starting from your initial circuit, it can be turned into our current implementation by permuting the 0th wire with the 1st and 2nd one.

We’ll correct the scoring system in the upcoming weeks and follow up here once it’s done.  
Thanks again for taking the time to flag this issue, this really helps us improve the Codebook!

---

<div class="post-metadata">

**Author:** ![Anton\_Naumov](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/anton_naumov/32/3519_2.png) [@Anton\_Naumov](https://discuss.pennylane.ai/u/Anton_Naumov)\
**Post date:** [July 31, 2026, 12:56pm UTC](https://discuss.pennylane.ai/t/codexercise-i-13-5-possible-bug/9416/4 "2026-07-31T12:56:37Z")

</div>

Thanks, happy to be of use 🙂

---

<div class="post-metadata">

**Author:** ![gabriela](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@gabriela](https://discuss.pennylane.ai/u/gabriela)\
**Post date:** [August 13, 2026, 3:49pm UTC](https://discuss.pennylane.ai/t/codexercise-i-13-5-possible-bug/9416/5 "2026-08-13T15:49:53Z")

</div>

Hi @Anton_Naumov,  
I just wanted to let you know that we have fixed this codercise 🙂  
Thanks again for letting us know and I hope you continue enjoying the exercises!
