start and goal. You may apply this operation to start any number of times:
- pick two different indices i and j;
- at the same time, replace start[i] with start[i] OR start[j] and start[j] with start[i] XOR start[j] (both formulas use the old values).
For example, "0110" with i = 0, j = 2 becomes "1110".
Return True if start can be turned into goal this way, and False otherwise.start="001", goal="110" → True
i = 0, j = 2: "001" → "101". Then i = 1, j = 2: "101" → "111". Finally i = 0, j = 2: 1 OR 1 = 1 and 1 XOR 1 = 0, giving "110".
start="000", goal="010" → False
Operations on zeros only ever produce zeros: 0 OR 0 = 0 and 0 XOR 0 = 0. There is no way to create a 1.
start="10", goal="00" → False
Once there is a 1 it cannot be destroyed: with a pair (1, x) position i keeps 1 OR x = 1, and with (0, 1) position i becomes 1.
0 and 1start="001", goal="110"
True
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.