A function f on n bits hides a string s: two different inputs give the same output exactly when they differ by s, that is f(x) = f(x') if and only if x' = x or x' = x \oplus s (\oplus is bitwise XOR). When s is all zeros, f never repeats an output. Each run of Simon's quantum circuit on f ends with a measured string y of n bits that satisfies
where y_k and s_k are character k of the strings (qubit 0 is the leftmost character). The lab notebook ys lists the strings measured in several runs; it may repeat a string or contain the all-zeros string.
The notebook has been kept long enough that it pins down s: either exactly one string z other than all zeros satisfies y\cdot z = 0 for every y in ys (then s = z), or none does (then s is all zeros). Write simon_secret(n, ys) that returns s as a string of n characters "0"/"1".
The larger tests use the helper simon_log(n, seed), which picks a hidden s from seed and returns a notebook of measured strings that pins it down; you may use it with Run.
Examples
Input: n = 3, ys = ["011", "100"]
Output: "011"
Explanation: "100" forces s0 = 0 and "011" forces s1 = s2; the only choice
besides "000" is "011".
Input: n = 2, ys = ["11", "00", "11"]
Output: "11"
Input: n = 3, ys = ["110", "011", "111"]
Output: "000"
Constraints
1 <= n <= 40,1 <= len(ys) <= 200; each string has lengthn- trying all 2^n candidates is far too slow for the largest
n
Goals
- Turn measured strings y with y . s = 0 (mod 2) into a system of linear equations over GF(2)
- Solve it by elimination with XOR instead of searching all 2^n candidates
- Recognise when only the all-zeros string solves it