--- title: "TS2068 Subroutine Adds Intelligence to Programs" type: "article" slug: "ts2068-subroutine-adds-intelligence-to-programs" url: "http://localhost/article/ts2068-subroutine-adds-intelligence-to-programs/" markdown_url: "http://localhost/article/ts2068-subroutine-adds-intelligence-to-programs.md" published_at: "2022-09-14T02:44:54+00:00" modified_at: "2026-08-08T21:01:42+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "Computer users are painfully aware of the need to input information perfectly if a computer program is to understand them. Here’s a short subroutine that adds intelligence to your programs to make them user friendly. It will compare a user’s input to a list of words that a computer is expecting. If an exact match…" category: - name: "Quarters" slug: "quarters" taxonomy: "category" url: "http://localhost/category/periodicals/quarters/" post_tag: - name: "Best of Timex/Sinclair 2068 Articles and Documents" slug: "ts2068best" taxonomy: "post_tag" url: "http://localhost/tag/ts2068best/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" - name: "Type-in program" slug: "type-in-program" taxonomy: "post_tag" url: "http://localhost/tag/type-in-program/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" indiv: - name: "Thomas Beutel" slug: "thomas-beutel" taxonomy: "indiv" url: "http://localhost/indiv/thomas-beutel/" publication_r: id: 21505 title: "QuarTerS" type: "periodical" url: "http://localhost/periodical/quarters/" authors: "Thomas Beutel" authors_r: - name: "Thomas Beutel" slug: "thomas-beutel" taxonomy: "indiv" url: "http://localhost/indiv/thomas-beutel/" issues_articles: - id: 39505 title: "Quarters Spring 1985" type: "issue" url: "http://localhost/issue/quarters-spring-1985/" pages: "3" pubdate: "Spring 1985" archive_link: false --- # TS2068 Subroutine Adds Intelligence to Programs Computer users are painfully aware of the need to input information perfectly if a computer program is to understand them. Here’s a short subroutine that adds intelligence to your programs to make them user friendly. It will compare a user’s input to a list of words that a computer is expecting. If an exact match is not found it calculates the best match based on the similarity of the letters in the words. This allows the program to accept user inputs with typos rather than make the user enter the info again. ``` 1000 RESTORE 1100: REM WORD LIST POINTER 1005 LET R=0: LET C$="" 1010 READ B$: IF B$="*" THEN RETURN 1015 IF B$=A$ THEN LET C$=B*: RETURN 1020 LET T=0 1025 FOR I=1 TO LEN A$ 1030 FOR J=1 TO LEN B$ 1035 IF ABS(J-I)>3 THEN GOTO 1045 1040 IF A$(I)=B$(J) THEN LET T=T+2 (3-(ABS(J-I))) 1045 NEXT J 1050 NEXT I 1055 IF T>R THEN R=T: LET C$=B$ 1060 GOTO 1010 ``` Best matches are found by calculating a score for letter-to-letter similarity. If two matching letters are in the same position, 8 points are added to the total score. If they are off by one position, 4 points are added. Two positions off adds 2 points and three positions off adds 1 point. If the matching letters are more than three positions apart nothing is added. Once all letters are checked, the word is ranked and the word with the highest score is returned. A sample program and word list is shown below. Note that the input to the routine is C$, and the last list entry is a “*”. Run the program and input one of the choices on the list with a typo in it. The routine will probably print the word that meant to type. ``` 10 INPUT "ENTER A WORD: "; A$ 20 GOSUB 1000 30 PRINT "THE CLOSEST MATCH IS ";C$ 40 STOP 1100 DATA "INTERROGATE", "INTEGRATE", "INSPECT", "INNOVATE" 1110 DATA "IMPORT", "ILLUMINATE" , "INTERNATIONAL", "*" ```