In the applet below, clicking on a button (triangles on the sides of the board) swaps board
colors either in a whole row or in a whole column. Is it possible to have all squares but
one white?

Experiment with the applet before looking for a solution.

The puzzle is not very sophisticated. After playing with it awhile I have observed that some
quantities of black squares never come up. One can't get 1 black square, but also I never succeeded
in getting 2, 3 if n>3, or 4 if n>4, etc. squares. Also the emerging patterns seemed frequently to
repeat themselves in a monotonous manner. At this point I tried to classify patterns.

First of all, note that number of black and white squares stays invariant after swapping any two rows
or any two columns. Furthermore, consider two configurations in which, say, two columns have been swapped,
but otherwise identical. There is an important observation:

After an arbitrary sequence of moves applied to the two configurations, the number of black squares in both
will be identical.

The fact bears a rigorous proof. Since the two configurations have identical columns, column moves really
do not introduce additional differences. In each row, two squares have been swapped, but otherwise configurations
are identical. Therefore, row operations too do not change the relative number of black squares.

Now, let's say that two configurations are equivalent if

they have the same number of black squares, and

no legal move applied to both configurations changes the fact #1.

We just saw that swapping two columns (or two rows) results in an equivalent configuration. By the same token,
swapping columns and/or rows repeatedly generates a sequence of equivalent configurations. Thus, the starting
configuration is equivalent to the one on right. The center point of the grid splits the board into four
regions. Actually, every configuration is equivalent to a similar four region one (can you establish this?)

The four region configurations differ by the location of the center of the cross that splits the board.
The legal moves may be thought of as changing its location. For example, changing colors in row 1 moves the spot
one node up. Moves on the row 2, columns 3 or 4 move it down, left, and right, respectively. Let a and b
be coordinates of the center of the cross. Then the number of black squares is defined by the following function:

f(a,b) = a(n-b) + b(n-a)

The function has two symmetric properties: f(a,b) = f(n-a,n-b) and f(a,b) = f(b,a) which help save some effort when
trying to list its values. For small values of n it's quite feasible to list all possible values
of f for both a and b changing between 0 and n. For example, if n=3 we have:

It appears that, for every n, no configuration may actually have the number of black squares
between 0 and n, 1 in particular. Do you see a general proof of this result?