Soundex is an algorithm for creating indices for words based on their pronunciation.



Task

The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article).

Caution

There is a major issue in many of the implementations concerning the separation of two consonants that have the same soundex code! According to the official Rules [[1]]. So check for instance if Ashcraft is coded to A-261.

 If a vowel (A, E, I, O, U) separates two consonants that have the same soundex code, the consonant to the right of the vowel is coded. Tymczak is coded as T-522 (T, 5 for the M, 2 for the C, Z ignored (see "Side-by-Side" rule above), 2 for the K). Since the vowel "A" separates the Z and K, the K is coded.
 If "H" or "W" separate two consonants that have the same soundex code, the consonant to the right of the vowel is not coded. Example: Ashcraft is coded A-261 (A, 2 for the S, C ignored, 6 for the R, 1 for the F). It is not coded A-226.


100 PROGRAM "Soundex.bas"
110 FOR I=1 TO 20
120   READ NAME$
130   PRINT """";NAME$;"""";TAB(20);SOUNDEX$(NAME$)
140 NEXT 
150 DEF SOUNDEX$(NAME$)
160   NUMERIC I,N,P
170   LET NAME$=UCASE$(NAME$):LET S$=NAME$(1)
180   LET N$="01230129022455012623019202"
190   LET P=VAL(N$(ORD(S$)-64))
200   FOR I=2 TO LEN(NAME$)
210     LET N=VAL(N$(ORD(NAME$(I))-64))
220     IF N<>0 AND N<>9 AND N<>P THEN LET S$=S$&STR$(N)
230     IF N<>9 THEN LET P=N
240   NEXT 
250   LET S$=S$&"000"
260   LET SOUNDEX$=S$(1:4)
270 END DEF 
280 DATA Aschraft,Ashcroft,Euler,Gauss,Ghosh,Hilbert,Heilbronn,Lee,Lissajous,Lloyd
290 DATA Moses,Pfister,Robert,Rupert,Rubin,Tymczak,VanDeusen,Wheaton,Soundex,Example