LOMEM=768
10 DIM A$(81),B$(81),C$(81),D$(9)
20 PRINT "LARRY NELSON'S SUDOKU FOR THE APPLE I"      
30 PRINT: INPUT"WANT INSTRUCTIONS",D$:IF D$(1,1)="Y" THEN GOSUB 1000
40 PRINT"CREATING..";
50 GOSUB 4000
60 GOSUB 5000
70 GOSUB 3000
80 GOSUB 7000
90 GOSUB 6100
100 PRINT "  1=NEW PUZZLE": PRINT"  2=ANSWER TO PUZZLE": PRINT"  3=QUIT"
110 INPUT A
120 IF A=1 THEN 40 
130 IF A=2 THEN GOSUB 6000
140 IF A=3 THEN END
150 GOTO 100
1000 PRINT"SUDOKU IS A NUMBER PUZZLE IN A 9X9 GRID."
1010 PRINT"THE GRID IS SPLIT INTO 9 3X3 MINI-GRIDS."
1020 PRINT"SINGLE DIGITS FILL THE GRID. THE DIGITS"
1040 PRINT"MAY BE IN ANY ORDER. THERE ARE JUST"
1050 PRINT"THREE RULES FOR SOLVING THE GRID--"
1060 PRINT"-EACH ROW MUST HAVE ALL THE DIGITS 1-9."
1070 PRINT"-EACH COLUMN HAS ALL THE DIGITS 1-9."
1080 PRINT"-EACH MINI-GRID MUST ALSO HAVE ALL THE"
1090 PRINT"  DIGITS FROM 1-9."
1100 PRINT:INPUT"  HIT ENTER TO CONTINUE",D$
1110 RETURN
3000 PRINT ".";
3010 A$=B$
3020 FOR I=1 TO 7 STEP 3
3030 X=RND(6)
3040 IF X=0 THEN 3160
3050 Y=0:Z=2
3060 IF X=1 THEN Y=1
3070 IF X=3 THEN Z=1
3080 GOSUB 3400
3090 IF X<4 THEN 3160
3100 IF X=5 THEN 3130
3110 Z=1:GOSUB 3400
3120 GOTO 3160
3130 Y=1:GOSUB 3400
3160 NEXT I
3170 B$=A$
3180 RETURN
3400 FOR J=0 TO 8
3410 C$=A$
3420 W=9*J+I+Y:V=9*J+I+Z
3430 A$(W)=C$(V,V)
3440 A$(W+1)=C$(W+1)
3450 A$(V)=C$(W,W)
3460 IF V<81 THEN A$(V+1)=C$(V+1)
3470 NEXT J
3480 RETURN
4000 PRINT ".";
4010 A$="123456789"
4020 FOR I=1 TO 30:D$=""
4030 X=RND(8)+1:Y=RND(8)+2
4035 IF X>=Y THEN 4030
4040 B$=A$(Y,Y):C$=A$(X,X)
4050 IF X>1 THEN D$=A$(1,X-1)
4060 D$(LEN(D$)+1)=B$
4070 D$(LEN(D$)+1)=A$(X+1,Y-1)      
4080 D$(LEN(D$)+1)=C$
4090 IF Y<9 THEN D$(LEN(D$)+1)=A$(Y+1,9)
4100 A$=D$
4110 NEXT I
4120 RETURN
5000 PRINT".";
5010 A$(LEN(A$)+1)=A$:B$=""
5020 FOR I=0 TO 2
5030 FOR J=1 TO 7 STEP 3
5040 B$(LEN(B$)+1)=A$(I+J,I+J+8)
5050 NEXT J,I
5060 RETURN
6000 REM
6010 INPUT "ARE YOU SURE YOU WANT THE ANSWER (Y/N)",D$
6020 IF D$#"Y" THEN RETURN 
6030 A$=B$
6100 PRINT : PRINT "====================================="
6110 FOR J=0 TO 8
6120 PRINT "#";
6130 FOR I=1 TO 9:K=9*J+I
6140 PRINT " ";A$(K,K);" ";
6150 IF I MOD 3=0 THEN PRINT "#";
6160 IF I MOD 3>0 THEN PRINT ":";
6170 NEXT I
6175 PRINT 
6180 IF (J+1) MOD 3>0 THEN PRINT"-------------------------------------"
6190 IF (J+1) MOD 3=0 THEN PRINT"====================================="
6200 NEXT J
6210 PRINT
6220 INPUT "HIT ENTER TO CONTINUE",D$
6230 RETURN
7000 REM
7010 A$=B$
7020 PRINT "HOW DIFFICULT DO YOU WANT YOUR PUZZLE":PRINT "  1=EASY": PRINT "  2=MEDIUM": PRINT "  3=HARD"
7030 INPUT A
7040 IF A<1 OR A>3 THEN 7020
7050 W=2*A+20+RND(2)
7060 FOR I=1 TO W
7070 X= RND (81)+1
7080 IF A$(X,X)=" " THEN 7070
7090 GOSUB 7500
7100 X=82-X
7110 GOSUB 7500
7120 NEXT I
7130 RETURN 
7500 C$=A$
7510 A$(X)=" "
7520 IF X<81 THEN A$(X+1)=C$(X+1)
7530 RETURN
RUN
