10 REM NUMBER SQUARE GAME
20 REM FROM MICROCOMPUTING JUNE 81
30 REM BY MARC I. LEAVY, M.D.
40 LET L=0
50 DIGITS=0
60 PRINT CHR$(26):PRINT:PRINT
70 PRINT "                NUMBER SQUARES"
80 PRINT "                --------------"
90 PRINT:PRINT
100 PRINT "        WELCOME TO THE WORLD OF CONFUSION."
110 PRINT:PRINT
120 PRINT "    THERE ARE TWO VERSIONS OF NUMBER SQUARES:"
130 PRINT:PRINT
140 PRINT "                 1 - SEQUENTIAL"
150 PRINT "                 2 - MAGIC SQUARE"
160 PRINT:PRINT:PRINT
170 INPUT "             WHICH WOULD YOU LIKE? ",T
180 IF T=1 GOTO 340
190 IF T<>2 GOTO 170
200 REM
210 REM SET UP MAGIC SQUARE BOARD
220 REM
230 REM
240 FOR I=1 TO 4
250 FOR J=1 TO 4
260 READ M(I,J)
270 LET B(I,J)=M(I,J)
280 NEXT J
290 NEXT I
300 DATA 1,6,15,8,12,11,2,5,10,13,4,3,7,16,9,14
310 LET I1=4
320 LET J1=2
330 GOTO 470
340 REM
350 REM SET UP SEQUENTIAL BOARD
360 REM
370 REM
380 DIM B(4,4)
390 FOR I=1 TO 4
400 FOR J=1 TO 4
410 LET B(I,J)=(I-1)*4+J
420 NEXT J
430 NEXT I
440 LET I1=4
450 LET J1=4
460 REM
470 REM NOW SCRAMBLE THE BOARD 200 TIMES
480 REM
490 REM
500 PRINT:PRINT
510 PRINT "          I AM NOW SCRAMBLING THE BOARD"
520 FOR Q=1 TO 200
530 LET M=INT(1+RND*4)
540 ON M GOTO 550,600,650,700
550 IF I1=1 GOTO 530
560 LET B(I1,J1)=B(I1-1,J1)
570 LET B(I1-1,J1)=16
580 LET I1=I1-1
590 GOTO 740
600 IF I1=4 GOTO 530
610 LET B(I1,J1)=B(I1+1,J1)
620 LET B(I1+1,J1)=16
630 LET I1=I1+1
640 GOTO 740
650 IF J1=1 GOTO 530
660 LET B(I1,J1)=B(I1,J1-1)
670 LET B(I1,J1-1)=16
680 LET J1=J1-1
690 GOTO 740
700 IF J1=4 GOTO 530
710 LET B(I1,J1)=B(I1,J1+1)
720 LET B(I1,J1+1)=16
730 LET J1=J1+1
740 NEXT Q
750 REM
760 REM PRINT BOARD
770 REM
780 LET M9=0
790 REM OUTPUT A HOME SCREEN
800 PRINT CHR$(26)
810 PRINT:PRINT
820 PRINT "              ---------------------"
830 FOR I=1 TO 4
840 PRINT "              ";
850 FOR J=1 TO 4
860 PRINT ":";
870 IF B(I,J)=16 THEN PRINT "    ";:GOTO 900
880 IF B(I,J)<10 THEN PRINT " ";
890 PRINT B(I,J);
900 NEXT J
910 PRINT ":"
920 PRINT "              ";"---------------------"
930 NEXT I
940 REM
950 REM ERASE REST OF SCREEN AND BEEP
960 REM FOR INPUT
970 REM
980 PRINT CHR$(22);CHR$(7);CHR$(7);
990 REM
1000 REM INPUT MOVE
1010 REM
1020 PRINT:PRINT
1030 INPUT "               MOVE WHICH PIECE? ",M
1040 LET I1=0:J1=0
1050 FOR I=1 TO 4
1060 FOR J=1 TO 4
1070 IF B(I,J)=M THEN I1=I:J1=J
1080 NEXT J
1090 NEXT I
1100 PRINT
1110 IF I1=0 THEN PRINT "             I CAN'T FIND THAT NUMBER":GOTO 1000
1120 LET I2=0:J2=0
1130 FOR I=I1-1 TO I1+1
1140 IF I>4 GOTO 1170
1150 IF I<1 GOTO 1170
1160 IF B(I,J1)=16 THEN I2=I:J2=J1:GOTO 1250
1170 NEXT I
1180 FOR J=J1-1 TO J1+1
1190 IF J>4 GOTO 1220
1200 IF J<1 GOTO 1220
1210 IF B(I1,J)=16 THEN I2=I1:J2=J:GOTO 1250
1220 NEXT J
1230 LET M9=M9+1
1240 PRINT "               NOT A VALID MOVE":GOTO 1000
1250 LET B(I2,J2)=M
1260 LET B(I1,J1)=16
1270 ON T GOTO 1290,1400
1280 REM
1290 REM SEQUENTIAL SOLUTION
1300 REM
1310 LET C=0
1320 FOR I=1 TO 4
1330 FOR J=1 TO 4
1340 IF B(I,J)<C GOTO 760
1350 LET C=B(I,J)
1360 NEXT J
1370 NEXT I
1380 PRINT "YOU GOT IT!!"
1390 GOTO 1540
1400 REM
1410 REM MAGIC SQUARE SOLUTION
1420 REM CHECK
1430 REM
1440 FOR I=1 TO 4
1450 FOR J=1 TO 4
1460 IF B(I,J)<>M(I,J) GOTO 760
1470 NEXT J
1480 NEXT I
1490 REM
1500 REM A WIN IS DECLARED
1510 REM
1520 PRINT "        THAT IS THE CORRECT SOLUTION"
1530 PRINT
1540 INPUT "        LIKE TO PLAY ANOTHER GAME? ",I$
1550 IF LEFT$(I$,1)="Y" THEN RUN
1560 END
ORRECT SOLUTION"
15