10 REM Eliza from Creative Computing
20 REM     -----INITIALIZATION-----
21 DEFINT A-Z:CLS$=CHR$(27)+"*"
30 DIM S(36),R(36),N(36)
40 N1=36:N2=12:N3=112
50 FOR X=1 TO N1+N2+N3:READ Z$:NEXT X:REM SAME AS RESTORE
60 FOR X=1 TO N1
70 READ S(X),L:R(X)=S(X):N(X)=S(X)+L-1
80 NEXT X
90 PRINT CLS$;"My name is Eliza.  I'm a Computer.  I have been programmed"
100 PRINT "to assist humans with their problems.  But first, can you give"
101 PRINT "me a ";:RANDOMIZE
102 INPUT "What is your name";NAM$
103 PRINT "So, ";NAM$;", what is the problem?"
110 REM *** User input ***
120 LINE INPUT I$:IF LEN(I$)=0 THEN RUN "I"
130 I$=" "+I$+"  "
140 REM  GET RID OF APOSTROPHES
150 O$=" ":FOR L=1 TO LEN(I$)
160 IL=ASC(MID$(I$,L,1))
170 IF IL=32 AND RIGHT$(O$,1)<>" " THEN 210
180 IF IL<65 THEN 220:REM strip punctuation, numbers
190 IF IL<96 THEN IL=IL+32:REM make small
200 IF IL>122 THEN 220
210 O$=O$+CHR$(IL):REM add character
220 NEXT L
230 I$=O$
250 REM *** Find keyword in I$ ***
260 RESTORE
270 S=0
280 FOR K=1 TO N1
290 READ K$
300 IF S>0 THEN 330
310 L=INSTR(I$," "+K$+" ")
320 IF L>0 THEN S=K:T=L:F$=K$
330 NEXT K
340 IF S>0 THEN K=S:L=T:GOTO 360
350 K=36:GOTO 490:REM  WE DIDN'T FIND ANY KEYWORDS
360 REM *** Perform string swaps for persons ***
370 RESTORE:FOR X=1 TO N1:READ Z$:NEXT X:REM SKIP OVER KEYWORDS
380 C$=" "+MID$(I$,L+LEN(F$)+2):C$=LEFT$(C$,LEN(C$)-1):REM strip space
390 FOR X=1 TO N2/2
400 READ S$,R$
410 S$=" "+S$+" ":R$=" "+R$+" "
420 L=INSTR(C$,S$):IF L=0 THEN 450
430 C$=LEFT$(C$,L-1)+R$+MID$(C$,L+LEN(S$))
440 GOTO 480
450 L=INSTR(C$,R$):IF L=0 THEN 480
460 C$=LEFT$(C$,L-1)+S$+MID$(C$,L+LEN(R$))
470 L=L+LEN(S$)
480 NEXT X
490 REM *** Use keyword number K to select reply ***
500 RESTORE:FOR X= 1 TO N1+N2:READ Z$:NEXT X
510 FOR X=1 TO R(K):READ F$:NEXT X:REM  READ RIGHT REPLY
520 R(K)=R(K)+1: IF R(K)>N(K) THEN R(K)=S(K)
530 PRINT LEFT$(F$,LEN(F$)-1);
531 IF RIGHT$(F$,1)="/" THEN PRINT:GOTO 110
540 PRINT C$;RIGHT$(F$,1):GOTO 110
560 REM *** Program data ***
570 REM *** Keywords ***
580 DATA "can you","can i","you are","youre","i dont","i feel"
590 DATA "why dont you","why cant i","are you","i cant","i am","im"
600 DATA "you","i want","what","how","who","where","when","why"
610 DATA "name","cause","sorry","dream","hello","hi","maybe"
620 DATA "no","your","always","think","alike","yes","friend"
630 DATA "computer","nokeyfound"
640 REM *** Swap pronoun data ***
650 DATA "are","am","were","was","you","i","your","my"
660 DATA "ive","youve","im","youre"
670 REM *** Replies (End / for no cont, else ?,. or !) ***
680 DATA "Don't you believe that I can?"
690 DATA "Perhaps you would like to be able to."
700 DATA "You want me to be able to?"
710 DATA "Perhaps you don't want to?"
720 DATA "Do you want to be able to?"
730 DATA "What makes you think I am?"
740 DATA "Does it make you happy to think I am?"
750 DATA "Perhaps you would like to be."
760 DATA "Do you sometimes wish you were?"
770 DATA "So you don't?"
780 DATA "Why don't you?"
790 DATA "So you'd like to!"
800 DATA "Does this bother you?/"
810 DATA "I'd like to know more!"
820 DATA "Do you often feel?"
830 DATA "Do you enjoy feeling?"
840 DATA "Do you really believe I don't?"
850 DATA "Perhaps, in my own time, I will."
860 DATA "Do you want me to?
870 DATA "Do you think I should be able to?
880 DATA "Why can't you?"
890 DATA "Why are you interested in whether or not I am?"
900 DATA "Would you prefer I were not?"
910 DATA "PERHAPS IN YOUR FANTASIES I AM*"
920 DATA "How do you know you can't?
930 DATA "Have you tried?/"
940 DATA "Perhaps you can, now,!"
950 DATA "So you came to me because you are."
960 DATA "How long have you been?"
970 DATA "Do you think it is normal to be?"
980 DATA "Do you enjoy being?"
990 DATA "Let's get back to your problem./"
1000 DATA "Oh, I?"
1010 DATA "Well, let's talk about you for a while now./"
1020 DATA "What would it mean to you if you got?"
1030 DATA "Why do you want?"
1040 DATA "Suppose you soon got."
1050 DATA "What if you never got?"
1060 DATA "Sometimes I also want."
1070 DATA "Why do you ask?/"
1080 DATA "Does that question interest you?/"
1090 DATA "What answer would please you most?/"
1100 DATA "What do you think?/"
1110 DATA "Are such questions on your mind often?/"
1120 DATA "What do you really want to know?/"
1130 DATA "Have you asked anyone else?/"
1140 DATA "Have you asked these questions before?/"
1150 DATA "What exactly are you thinking about?/"
1160 DATA "Well, let's be nice, now./"
1170 DATA "Let's not talk about people behind their back./"
1180 DATA "Is that the real reason?/"
1190 DATA "Any other reasons?/"
1200 DATA "Does that reason explain anything else?/"
1210 DATA "What other reasons might there be?/"
1220 DATA "Oh, excuse me!/"
1230 DATA "No hard feelings, now./"
1240 DATA "Why do you feel sorry?/"
1250 DATA "Listen, I'm on your side./"
1260 DATA "What does the dream suggest to you?/"
1270 DATA "Do you dream often?/"
1280 DATA "It must be nice to have dreams.  I don't.../"
1290 DATA "The dream comes from deep in your mind./"
1300 DATA "Well, how do you do!  Can I help you?/"
1310 DATA "You seem somewhat uncertain./"
1320 DATA "Why the uncertain tone?/"
1330 DATA "Can you be more positive?/"
1340 DATA "You aren't sure?/"
1350 DATA "You don't know?/"
1360 DATA "Oh.  Well, then, what?"
1370 DATA "You seem a little negative./"
1380 DATA "Why not?/","Are you sure?/","Why 'No'?/"
1410 DATA "Why are you worried about my?"
1420 DATA "What about your own?"
1430 DATA "Can you think of a specific example?/"
1440 DATA "When?/"
1450 DATA "What are you thinking of?/"
1460 DATA "Oh, nothing is Always the same./"
1470 DATA "Think so?/"
1480 DATA "But you aren't sure you."
1490 DATA "Do you doubt you?"
1500 DATA "In what way?/"
1510 DATA "What resemblance do you see?/"
1520 DATA "What does the similarity suggest to you?/"
1530 DATA "What other connections do you see?/"
1540 DATA "Could there really be some connection?/"
1550 DATA "How?/"
1560 DATA "You seem rather sure of this!/"
1570 DATA "Are you sure?/"
1580 DATA "I see./","Aha!/"
1600 DATA "What about your friends?/"
1610 DATA "Do your friends worry you?/"
1620 DATA "I think they probably mean well./"
1630 DATA "Perhaps you should be more open with your friends./"
1640 DATA "Do you like your friends?/"
1650 DATA "Well, everyone needs friends./"
1660 DATA "Remember, I am a computer./"
1670 DATA "Meaning me, perhaps?/"
1680 DATA "Think of me as a friend./"
1690 DATA "What about computers?/"
1700 DATA "So machines are part of the problem?/"
1710 DATA "I like to think computers can help people./"
1720 DATA "Sometimes computers do cause people problems./"
1730 DATA "So what seems to be the problem?/"
1740 DATA "So what does this suggest to you?/"
1750 DATA "I see./"
1760 DATA "I'm not sure I understand you fully./"
1770 DATA "Could you be more specific?/"
1780 DATA "Can you elaborate on that?/"
1790 DATA "That's interesting!/"
1810 REM *** Data for selecting replies ***
1830 DATA 1,3,4,2,6,4,6,4,10,4,14,3,17,3,20,2,22,3,25,3
1840 DATA 28,4,28,4,32,3,35,5,40,9,40,9,40,9,40,9,40,9,40,9
1850 DATA 49,2,51,4,55,4,59,4,63,1,63,1,64,5,69,5,74,2,76,4
1860 DATA 80,3,83,7,90,3,93,6,99,7,106,6
,9,40,9,40,9,40,9,40,9
1850 DATA 49,2,51,4,55,4,59,4,63,1,63,1,64,5,69,5,74,2,76,4
1860 DATA 80,3,83,7