a new version
public static boolean disco(boolean[] init, boolean[] target) { return recurse(init,boolean,0); } public static boolean recurse(boolean[] init, boolean[] target, int min) { if (min == init.length) if (init == target) return true; else return false; boolean[] temp = "init with a change at min"; boolean a = recurse(init, target, min+1); boolean b = recurse(temp, target, min+1); return a||b; }
new new version
I broke it into three cases:
Case 1: Length% 3 = 0
Changing the first lamp and the second lamp, you can affect the change only on the 3rd. Then a change to 4 and 5 will make the 6th, only one will change. We see that we can change each lamp with an index divisible by 3.
Working backward (starting from the end), we can do the same, but this time it shows us that we can change bulbs with an index (i + 1) divisible by 3.
Combining the two, we see that if we want to change the index of 0.1 mod 3, we can. But then, to change 2, we just have to change the neighboring 0.1 pairs, and then make the change on average. Therefore, in all cases they are decidable.
Case 2: Length% 3 = 1
As in the first case, but we can influence individual changes at 0.2 mod 3 and, thus, compress 1 mod 3.
Case 3: Length% 3 = 2
Working back and forth only leads to cases of 0 mod 3. The only remaining moves we make are two changes in the bulbs (since we can ignore any changes in positions 0). A change of 1 or 2 will result in a change in position surrounded by two 0s, while a change in 0 will lead to a change in parity in neighboring blocks 1,2, which have 0 in between (this is easier if you draw it). But what I have shown so far is that 0 can be fixed, and in any neighboring 1,2 you can fix both if they are wrong without changing anything. If you are mistaken, you propagate the change to a neighboring pair of 1.2. If necessary, this change can be moved. This means that any even number of errors in 1.2 positions can be fixed, but an odd number cannot. All errors at position 0 can be corrected.
public static boolean disco(boolean[] init, boolean[] target) { if (init.length%3 == 0 || init.length%3 == 1) return true; return recurse(init,target,0, true); } public static boolean recurse(boolean[] init, boolean[] target, int index, boolean even) { if (index = init.length) return even; if (init[index] != target[index] && index%3 != 0) even = !even; return recurse(init, target, index+1, even); }