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.

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

        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
    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