10 '	******************************************
20 '	** W O R D  S E A R C H  P U Z Z L E    **
30 '	******************************************
40 '	** ADAPTED FROM CREATIVE COMPUTING      **
50 '	** FOR THE OSBORNE 1 COMPUTER           **
60 '	** USING MICROSOFT BASIC 5.0            **
70 '	** BY STEVE TURNER                      **
80 '    ** 12/1/1981                            **
90 '	******************************************
100 PRINT CHR$(26)
110 PRINT STRING$(52,160)
120 PRINT
130 GOSUB 1590
140 PRINT TAB(18)"WORD SEARCH PUZZLE"
150 GOSUB 1600
160 PRINT STRING$(52,160)
170 PRINT:PRINT"   THIS PROGRAM IS A WORD SEARCH PUZZLE GENERATOR"
180 PRINT"THE PROGRAM TAKES A SET OF WORDS, PURGES ALL NON-"
190 PRINT"ALPHABETIC CHARACTERS OUT OF THEM, AND INCORPORATES"
200 PRINT"THEM INTO A WORD SEARCH PUZZLE."
210 PRINT
220 PRINT"   IN THE COURSE OF MAKING THE PUZZLE, THE COMPUTER"
230 PRINT"MAY FIND THAT IT CAN'T PUT A PARTICULAR WORD ANY-"
240 PRINT"WHERE, AND SO WILL ASK YOU IF IT SHOULD START THE"
250 PRINT"WHOLE PUZZLE OVER.IF YOU DON'T WANT IT TO START OVER"
260 PRINT", ENTER 'NO', AND IT WILL THROW AWAY THAT PARTICULAR"
270 PRINT"WORD IF THIS PERSISTS, TRY EITHER GIVING LESS WORDS"
280 PRINT"OR BIGGER PUZZLE DIMENSIONS!"
290 PRINT:PRINT STRING$(52,160)
300 PRINT
310 CLEAR 3000
320 DEF FNA(Z)=INT(RND(1)*Z+1)
330 INPUT"HOW MANY COLUMNS DOES YOUR PRINTER HAVE";TW
340 WIDTH LPRINT(TW)
350 INPUT"DO YOU WANT A SOLUTION PRINTOUT";X$
360 INPUT"WHAT IS THE WIDTH OF THE PUZZLE";W:MD=W
370 IF W*2<=TW THEN 390
380 PRINT"THAT WILL NOT FIT IN ";TW;" COLUMNS.":GOTO 360
390 IF W<1 THEN 360
400 INPUT"THE LENGTH OF THE PUZZLE WILL BE ";L:IF L>W THEN MD=L
410 IF L<1 THEN 400
420 PRINT " MAXIMUM NUMBER OF WORDS TO USE IN THE PUZZLE"; 
430 INPUT M
440 IF M>=2 THEN 460
450 PRINT"SORRY; THERE MUST BE AT LEAST 2 WORDS.":GOTO 420
460 PRINT:LPRINT
470 DIM A$(L,W),W$(M)
480 DIM W(M,3),DXY(8,2),DD(28)
490 PRINT"NOW ENTER A HEADING THAT WILL BE PRINTED OVER"
500 PRINT"THE PUZZLE";" (";TW;" CHARACTERS MAXIMUM ! )"
510 INPUT XY$
520 PRINT"OK. . . ENTER A WORD AT EACH QUESTION MARK."
530 PRINT"TO REDO THE PREVIOUS WORD, TYPE A HYPHEN (-)."
540 PRINT"WHEN YOU RUN OUT OF WORDS, TYPE A PERIOD (.)."
550 FOR I=1 TO M
560 INPUT T$:IF T$="-" THEN I=I-1:PRINT"REDO ";W$(I);". . .":GOTO 560
570 IF T$="." THEN M=I-1:GOTO 770
580 IF LEN(T$)=0 THEN PRINT "INPUT ERROR; REDO:":GOTO 560
590 J=1
600 TE$=MID$(T$,J,1):IF TE$>="a" AND TE$<="z" THEN 670
610 IF TE$<"A" OR TE$>"Z" THEN 630
620 T$=LEFT$(T$,J-1)+CHR$(ASC(MID$(T$,J,1))+32)+RIGHT$(T$,LEN(T$)-J):GOTO 670
630 IF TE$=T$ THEN T$="":GOTO 580
640 IF J=LEN(T$) THEN T$=LEFT$(T$,J-1):GOTO 680
650 IF J=1 THEN T$=RIGHT$(T$,LEN(T$)-1):J=J-1:GOTO 670
660 T$=LEFT$(T$,J-1)+RIGHT$(T$,LEN(T$)-J):J=J-1
670 J=J+1:IF J<=LEN(T$) THEN 600
680 PRINT" - ";T$;" - "
690 IF LEN(T$)<=MD THEN 720
700 PRINT"THAT'S TOO LONG I'M AFRAID.";
710 PRINT"TRY ANOTHER ONE:":GOTO 560
720 FOR IZ=1 TO I-1:IF W$(IZ)<>T$ THEN NEXT:GOTO 740
730 PRINT"YOU ENTERED THAT ONE ALREADY. TRY ANOTHER:":GOTO 560
740 W$(I)=T$
750 NEXT I
760 PRINT"THAT'S IT . . . ";M;" WORDS."
770 PRINT"NOW LET ME THINK HOW TO DO THIS PUZZLE "
780 FOR I=1 TO M-1
790 FOR J=I+1 TO M
800 IF LEN(W$(I))< LEN(W$(J)) THEN HZ$=W$(I):W$(I)=W$(J):W$(J)=HZ$
810 NEXT:NEXT
820 FOR I=1 TO 8:READ DXY(I,1),DXY(I,2):NEXT
830 FOR I=1 TO 28:READ DD(I):NEXT
840 DATA 0,1,1,1,1,0,1,-1,0,-1,-1,-1,-1,0,-1,1
850 DATA 2,4,6,8,2,4,6,8,2,4,6,8,2,4,6,8,2,4,6,8,2,4,6,8,1,3,5,7
860 FOR I=1 TO M
870 LN=LEN(W$(I))
880 NT=0
890 SD=DD(FNA(28))
900 SX=FNA(W):X1=SX+(LN-1)*DXY(SD,1):IF X1<1 OR X1>W THEN 890
910 SY=FNA(L):X1=SY+(LN-1)*DXY(SD,2):IF X1<1 OR X1>L THEN 890
920 NT=NT+1:IF NT<>W*L*2 THEN 970
930 PRINT"COULD NOT FIT '";W$(I);"' IN THE PUZZLE."
940 INPUT"DO YOU WANT ME TO START OVER";A$
950 IF LEFT$(A$,1)="Y" OR LEFT$(A$,1)="y" THEN 860
960 W$(I)="":GOTO 1050
970 J=SY:K=SX
980 FOR P=1 TO LN
990 IF LEN(A$(J,K)) AND A$(J,K)<> MID$(W$(I),P,1) THEN 890
1000 J=J+DXY(SD,2):K=K+DXY(SD,1):NEXT P
1010 J=SY:K=SX
1020 FOR P=1 TO LN:A$(J,K)=MID$(W$(I),P,1)
1030 J=J+DXY(SD,2):K=K+DXY(SD,1):NEXT
1040 W(I,1)=SX:W(I,2)=SY:W(I,3)=SD
1050 NEXT I
1060 FOR I=1 TO L
1070 FOR J=1 TO W
1080 IF A$(I,J)="" THEN A$(I,J)=CHR$(FNA(26)+96)
1090 NEXT:NEXT
1100 FOR I=1 TO M-1:FOR J=I TO M
1110 IF W$(I)<=W$(J) THEN 1140
1120 HZ$=W$(I):W$(I)=W$(J):W$(J)=HZ$
1130 FOR K=1 TO 3:HZ=W(I,K):W(I,K)=W(J,K):W(J,K)=HZ:NEXT K
1140 NEXT J:NEXT I
1150 INPUT"HOW MANY COPIES OF THIS PUZZLE DO YOU WANT";N
1160 PRINT"FOR EACH COPY, HIT RETURN TO BEGIN PRINTING..."
1170 FOR C=1 TO N:GOSUB 1180:NEXT:GOTO 1450
1180 INPUT A$:PRINT
1190 LPRINT:LPRINT
1200 T=(TW-2*W)/2:PRINT
1210 LPRINT
1220 PRINT
1230 LPRINT
1240 PRINT TAB(5);XY$
1250 LPRINT TAB((TW-LEN(XY$))/2);XY$
1260 PRINT
1270 LPRINT:LPRINT
1280 FOR J=1 TO L: PRINT ;
1290 LPRINT TAB(T);
1300 FOR K=1 TO W:IF A$(J,K)="." THEN PRINT". ";:LPRINT ". ";:GOTO 1330
1310 PRINT CHR$(ASC(A$(J,K))-32);" ";
1320 LPRINT CHR$(ASC(A$(J,K))-32);" ";
1330 NEXT:PRINT:LPRINT:NEXT
1340 PRINT
1350 LPRINT:LPRINT
1360 PRINT TAB(2)"FIND THESE HIDDEN WORDS IN THE ABOVE PUZZLE"
1370 LPRINT TAB(15)"FIND THESE HIDDEN WORDS IN THE ABOVE PUZZLE:"
1380 LPRINT
1390 FOR J=1 TO M:IF LEN(W$(J))=0 THEN 1430
1400 IF POS(0) + LEN(W$(J)) > TW-2 THEN LPRINT:PRINT
1410 PRINT W$(J),
1420 LPRINT W$(J),
1430 NEXT:LPRINT:LPRINT:LPRINT:LPRINT
1440 RETURN
1450 IF LEFT$(X$,1)="Y" OR LEFT$(X$,1)="y" THEN 1470
1460 END
1470 REM
1480 FOR I=1 TO L:FOR J=1 TO W:A$(I,J)=".":NEXT J:NEXT I
1490 FOR I=1 TO M
1500 LN=LEN(W$(I)):J=W(I,2):K=W(I,1)
1510 FOR P= 1 TO LN
1520 A$(J,K)=MID$(W$(I),P,1)
1530 J=J+DXY(W(I,3),2):K=K+DXY(W(I,3),1):NEXT P
1540 NEXT I
1550 XY$="ANSWER KEY:"
1560 GOSUB 1180
1570 PRINT:PRINT
1580 END
1590 PRINT CHR$(27);")";:RETURN
1600 PRINT CHR$(27);"(";:RETURN
="ANSWER KEY:"
1560 GOSUB 1180
1570 PRINT:PRINT
1580 END
1590 PRINT CHR$(27);")";:RETURN
1600 PRINT CHR$(27);"(