DECLARE FUNCTION isWord% (w$)
DECLARE SUB permute (a$)
CLS
a$ = "aabenpruy": h$ = a$
DO
w1$ = LEFT$(a$, 3): w2$ = MID$(a$, 4, 3): w3$ = RIGHT$(a$, 3)
w4$ = MID$(a$, 1, 1) + MID$(a$, 4, 1) + MID$(a$, 7, 1)
w5$ = MID$(a$, 2, 1) + MID$(a$, 5, 1) + MID$(a$, 8, 1)
w6$ = MID$(a$, 3, 1) + MID$(a$, 6, 1) + MID$(a$, 9, 1)
w7$ = MID$(a$, 1, 1) + MID$(a$, 5, 1) + MID$(a$, 9, 1)
w8$ = MID$(a$, 3, 1) + MID$(a$, 5, 1) + MID$(a$, 7, 1)
IF isWord(w1$) THEN
IF isWord(w2$) THEN
IF isWord(w3$) THEN
IF isWord(w4$) THEN
IF isWord(w5$) THEN
IF isWord(w6$) THEN
IF isWord(w7$) THEN
IF isWord(w8$) THEN
PRINT : PRINT w1$: PRINT w2$: PRINT w3$: PRINT
END IF
END IF
END IF
END IF
END IF
END IF
END IF
END IF
permute a$
LOOP UNTIL a$ = h$
DEFINT A-Z
FUNCTION isWord (w$)
n = LEN(w$)
IF w$ = "i" THEN isWord = 1: EXIT FUNCTION
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
finds
pea
urn
bay
and
pub
era
any
Since ARB is not a common word, the second one is the solution. A dictionary shows that "arb" is a word meaning "arbitrager", by shortening, as, for example, a "tux" is another word for a "tuxedo".
From the Page-A-Day 2009 "Mensa 365 Brain Puzzlers" calendar for 2009, July 11 page. (Abbie F. Salny, Mark Danna, and Fraser Simpson.)
|