EX A.4.2 Give me a tip for my solution plss, forgot it I think i found a bug

I have a question I’ve been trying this code for hours and I don’t know what I’m doing wrong

def parity_checker(combos):
    """Use multisol_pair_circuit to determine the parity of a solution set.

    Args:
        combos (list[list[int]]): A list of secret combinations.

    Returns: 
        int: The parity of the solution set.
    """
    parity = 0
    x_tilde_strs = [np.binary_repr(n, n_bits-1) for n in range(2**(n_bits-1))]
    x_tildes = [[int(s) for s in x_tilde_str] for x_tilde_str in x_tilde_strs]
    for x_tilde in x_tildes:
        probs = multisol_pair_circuit(x_tilde, combos)
        if np.isclose(probs[0], 1.0): 
            parity = 1
            break
    return parity

After running several times this code with diffrente combinations of probs[n] and 0 or 1 inside the np.isclose i notice that after using the value np.isclose(probs[0], 0.0) 1 time i got the correct answer, and the after trying to submit the answer again I show to me the message that my code was wrong, I don’t know if it is a bug, but maybe it is

Hi @Antonio_Ortiz, welcome to the Forum!

This is not a bug. For one particular case it worked but your solution is not one that will work in general (which is what the challenge requires).

Notice that the hint says “the state counts the number of solutions modulo 2”. So what if you have 2 solutions? Your code will make it look like there was just one solution because you exited the for loop after the first solution. You will need to make some changes inside your for loop in order to get the right answer. I hope this hint helps!

1 Like

Hey Antonio,
I guess the algorithm tries to convey the fact that there is more than one secret combination present that can open the lock and our goal is to count the parity of the number of solutions.
If you remember in exercise “Breaking the lock a bit faster (A.3.2)”, we already solved this when only one solution was present.
Now all we have to do is count all the solutions present and return modulo 2 of the solution to get the parity.

1 Like