# Is it Always Possible? Colour Flipping

There's a 4x4 square, where switches are either red or green. When you flip a switch, all the buttons on that row and column will change color.

Is every starting position possible to complete? If not how many are there that are impossible?

Note: To complete all tiles must be green!

Letting 1s be red and 0s be green, here's an example flip;

 1011
0010
1111
0000


After:

1001
0000
0000
0010


The button press for above was the 3rd column, 3rd row.

• It would be helpful to give a couple examples of button pushes. – Rob Watts Oct 30 '14 at 23:07
• Why? Is that part hard to understand? – warspyking Oct 30 '14 at 23:15
• For this puzzle it isn't too hard to understand, but in general it helps to make sure that people understand it correctly. – Rob Watts Oct 30 '14 at 23:19
• Do diagonals also get flipped in this example? I am writing a program to test it, but right now it only works if rows and columns are toggled. – mdc32 Oct 30 '14 at 23:30
• Created a JSfiddle for manual testing. jsfiddle.net/wgk7n8Lh/2 It's backwards, so it's more testing if you can get to a certain configuration. I can write a program for automatic testing if you want. – mdc32 Oct 31 '14 at 0:23

It's always possible.

In order to flip a single switch, you flip it once, and all switches in the same row or column, in any order. The switch itself will be flipped 7 times, the switches in same row or column 4 times, the other switches twice. Which means all other switches will stay the same color.

Example:

0000        0010        1101        1111        1101        0101        0001        0000
0010 -3,2-> 1101 -3,1-> 1111 -3,3-> 1101 -3,4-> 1111 -1,2-> 0000 -2,2-> 1111 -2,4-> 0000
0000        0010        0000        1111        1101        0101        0001        0000
0000        0010        0000        0010        1101        0101        0001        0000


Using this technique, we can switch the red switches to green one by one. It will not be the most efficient solution in most cases, but it is possible.

Credit goes to @mdc32, his JSFiddle gave me an awesome blackboard!

• If you want an efficient solution, note that the order in which you press buttons doesn't matter and pressing a button twice is equivalent to not pressing it at all, so you press each button a number of times equal to the number of greens in its rows and columns (counting itself, but only once) mod 2. This gives a maximum of 16 presses to solve. – frodoskywalker Oct 31 '14 at 9:25
• I fixed the mistake you noted. – warspyking Oct 31 '14 at 12:37
• @frodoskywalker: Good point! A nitpick: the goal is to get the whole thing green, not red, so you need to do the exact opposite of what you said. – ruakh Nov 1 '14 at 4:47

Just click all buttons one time in any order and you will convert all from red to green.

• The starting position isn't necessarily all red. – f'' Dec 12 '15 at 19:14