The game

Given an   N×N   square array of zeroes or ones in an initial configuration,   and a target configuration of zeroes and ones.



The game is to transform one to the other in as few moves as possible by inverting whole numbered rows or whole lettered
columns at once   (as one move).

In an inversion.   any  1  becomes  0,   and any  0  becomes  1  for that whole row or column.



Task

Create a program to score for the Flipping bits game.

 The game should create an original random target configuration and a starting configuration.
 Ensure that the starting position is never the target position.
 The target position must be guaranteed as reachable from the starting position.   (One possible way to do this is to generate the start position by legal flips from a random target position.   The flips will always be reversible back to the target from the given start position).
 The number of moves taken so far should be shown.


Show an example of a short game here, on this page, for a   3×3   array of bits.




10 DEFINT A-Z
20 PRINT "*** FLIP THE BITS ***"
30 INPUT "Board size";S
40 IF S<3 OR S>8 THEN PRINT "3 <= size <= 8": GOTO 30
50 RANDOMIZE
60 DIM B(S,S),G(S,S)
70 FOR X=1 TO S
80 FOR Y=1 TO S
90 B=INT(.5+RND(1))
100 B(X,Y)=B: G(X,Y)=B
110 NEXT Y,X
120 FOR A=0 TO 10+2*INT(10*RND(1))
130 R=INT(.5+RND(1))
140 N=1+INT(S*RND(1))
150 GOSUB 500
160 NEXT A: M=0
170 PRINT: M=M+1
180 PRINT " ==BOARD==";TAB(20);" ==GOAL=="
190 PRINT "   ";: GOSUB 400
200 PRINT TAB(20);"   ";: GOSUB 400
210 FOR N=1 TO S
220 FOR A=0 TO 1
230 PRINT TAB(A*20);CHR$(64+N);". ";
240 FOR C=1 TO S: IF A THEN B=G(C,N) ELSE B=B(C,N)
250 PRINT USING "# ";B;
260 NEXT C,A
270 PRINT
280 NEXT N
290 PRINT
300 LINE INPUT "Enter row or column: ";I$
310 IF LEN(I$)<>1 THEN 300 ELSE C=ASC(I$) OR 32
320 IF C<97 THEN N=C-48:R=0 ELSE N=C-96:R=1
330 IF N<1 OR N>S THEN 300 ELSE GOSUB 500
340 W=1=1
350 FOR X=1 TO S:FOR Y=1 TO S
360 W=W AND (B(X,Y)=G(X,Y))
370 NEXT Y,X
380 IF W THEN PRINT:PRINT "You win! Moves:";M:END
390 GOTO 170
400 FOR I=1 TO S: PRINT USING "# ";I;: NEXT I: RETURN
500 IF R THEN 510 ELSE 520
510 FOR I=1 TO S: B(I,N)=1-B(I,N): NEXT I: RETURN
520 FOR I=1 TO S: B(N,I)=1-B(N,I): NEXT I: RETURN