# H.1.1: The secret rule isn't giving the answer of the right length

**URL:** <https://discuss.pennylane.ai/t/h-1-1-the-secret-rule-isnt-giving-the-answer-of-the-right-length/8261>\
**Category:** Codebook\
**Created:** [March 20, 2025, 7:01pm UTC](https://discuss.pennylane.ai/t/h-1-1-the-secret-rule-isnt-giving-the-answer-of-the-right-length/8261 "2025-03-20T19:01:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mack.attack](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/mack.attack/32/2772_2.png) [@mack.attack](https://discuss.pennylane.ai/u/mack.attack)\
**Post date:** [March 20, 2025, 7:01pm UTC](https://discuss.pennylane.ai/t/h-1-1-the-secret-rule-isnt-giving-the-answer-of-the-right-length/8261/1 "2025-03-20T19:01:22Z")

</div>

The secret rule is nothing more than an array rotation. However, I used the append and slice method, rather than the concatenate method. Why does the append and slice method not work?

```auto
input = [1, 1, 0] # MODIFY EXAMPLE
output = secret_box(input)
print("The result of applying the secret box to ", input, "is ", output)
# We will secretly apply the function and return the result!

def deterministic_box(bits):
    """Guess the secret deterministic rule.
    
    Args:
        bits (list[int]): A list of bits representing an initial condition.
         
    Returns: 
        list[int]: The output bits measured after deterministic evolution.
    """
    ##################
    # YOUR CODE HERE #
    ##################
    bits.append(bits[0])
    return bits[1:] # MODIFY THIS

print(deterministic_box([1,0,0,1,0,0,0,1]))

```

---

<div class="post-metadata">

**Author:** ![daniela.murcillo](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/daniela.murcillo/32/3612_2.png) [@daniela.murcillo](https://discuss.pennylane.ai/u/daniela.murcillo)\
**Post date:** [March 21, 2025, 4:26pm UTC](https://discuss.pennylane.ai/t/h-1-1-the-secret-rule-isnt-giving-the-answer-of-the-right-length/8261/2 "2025-03-21T16:26:15Z")

</div>

Hi, @mack.attack !  
Thanks for this question, it really made me think! 🤔  
You spotted an interesting mistake.  
I see that your code outputs the right answer and our evaluation shouldn’t be giving an error. However, it is doing it and the reason is that when you use `append`, the input array is modified and our evaluation code does a check comparing the input and output lengths returning a `False` value, hence the error.  
Changing our evaluation code is a bit tricky and for that reason, I will add sentence in the exercise statement so it is clear that the function must preserve the input length.

---

<div class="post-metadata">

**Author:** ![mack.attack](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/mack.attack/32/2772_2.png) [@mack.attack](https://discuss.pennylane.ai/u/mack.attack)\
**Post date:** [March 26, 2025, 4:08am UTC](https://discuss.pennylane.ai/t/h-1-1-the-secret-rule-isnt-giving-the-answer-of-the-right-length/8261/3 "2025-03-26T04:08:22Z")

</div>

Thanks. I definitely used an in-place method, even though the method is expecting an out-of-place method. What is the benefits of having to code this out-of-place?

---

<div class="post-metadata">

**Author:** ![daniela.murcillo](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/daniela.murcillo/32/3612_2.png) [@daniela.murcillo](https://discuss.pennylane.ai/u/daniela.murcillo)\
**Post date:** [March 26, 2025, 2:52pm UTC](https://discuss.pennylane.ai/t/h-1-1-the-secret-rule-isnt-giving-the-answer-of-the-right-length/8261/4 "2025-03-26T14:52:59Z")

</div>

I believe that when we wrote this codercise and the evaluation code, we weren’t considering these two methods and only stick with one. However, now that you ask, I can come up with a reason for using a method that doesn’t modify the input: in a more general circuit, you may have subsequent computations to perform on that same input and you would like to preserve it as is.  
Thanks for your questions! I hope the Codebook experience keeps being fun and stimulating.
