The first word can't result in a decimal value greater than 999, and this program does a search:
DECLARE FUNCTION
isWord! (w$)
OPEN "\words\words3.txt" FOR BINARY AS #1
w$ = " "
DO
GET #1, , w$
IF EOF(1) THEN EXIT
DO
n = 0
FOR i = 1 TO 3
d = ASC(MID$(w$, i, 1)) - ASC("a")
n = 26 * n + d
NEXT
IF n <= 999 THEN
n$ = ""
FOR pn = 1 TO 3
r = n MOD 10
n = n \ 10
n$ = MID$("abcdefghij", r + 1, 1) + n$
NEXT
IF isWord(n$) THEN
PRINT w$, n$
END IF
END IF
LOOP
FUNCTION isWord (w$)
n = LEN(w$)
w1$ = SPACE$(n)
OPEN "\words\words\" + LTRIM$(STR$(n)) + ".txt" FOR BINARY AS #2
l = LOF(2) / n
low = 1: high = l
DO
mid = INT((low + high) / 2)
GET #2, (mid - 1) * n + 1, w1$
IF w1$ = w$ THEN isWord = 1: CLOSE 2: EXIT FUNCTION
IF w1$ < w$ THEN low = mid + 1: ELSE high = mid - 1
LOOP UNTIL low > high
isWord = 0
CLOSE 2
END FUNCTION
The results were:
aah aah
adz bad
ala cig
alp dab
and deb
awl fid
bah gid
bed hid
bee hie
The words beginning with "a" are leading-zero numbers, which is bad form. Of the remaining ones, the "bed", "hid" pair has the most common words.
Adapted from New Scientist, 5 August 2006, Enigma number 1403.
|