Post by B+ on May 21, 2019 15:12:34 GMT
Here is handy code to unscramble a set of letters. Can't say the word list file I used is all that complete, my 2nd try was letters for *corner* and it wasn't in the list! *cornerstore* was though.
Find "unixdict.txt" at justbasiccom.proboards.com/thread/241/word-lists
output sample:
PS used QB64 Editor to format and syntax check code (though some differences to JB).
Find "unixdict.txt" at justbasiccom.proboards.com/thread/241/word-lists
'Scramble Search Word List.txt B+ 2019-05-21
' This code uses "unixdict.txt" 25,104 items all lower case no compound words
' see tsh73 post ref: http://justbasiccom.proboards.com/thread/241/word-lists
' freshly downloaded 2019-05-21
'load file into big string
dictionaryFile$ = "unixdict.txt"
OPEN dictionaryFile$ FOR INPUT AS #1
INPUT #1, wds$
CLOSE #1
' maybe a little faster to split out words to an array?
' than to use WORD$(wds$, index), so do it once now!
' also might be faster to anaCode$ all the words too!
DIM ws$(25104)
FOR i = 1 TO 25104
ws$(i) = word$(wds$, i)
NEXT
' OK try the unscrambler to find words for given set of letters
DO
SCAN
CLS
PRINT "(Enter nothing to quit)"
INPUT "Enter a set of letters that might be a scrambled word: "; inp$
IF inp$ <> "" THEN
inpCode$ = anaCode$(inp$) 'compare all coded words in file to this code
wc = 0
LOCATE 1, 3 : PRINT "Search List:"
FOR i = 1 TO 25104
SCAN
LOCATE 14, 3: PRINT INT(i * 100 / 25104); "%";
test$ = anaCode$(ws$(i))
IF test$ = inpCode$ THEN
wc = wc + 1
LOCATE 1, 3 + wc
PRINT wc, ws$(i)
END IF
NEXT
LOCATE 1, 3 + wc + 1
PRINT : PRINT "OK, that was the end of the search."
INPUT "Press enter to continue, enter anything to quit... "; wate$
IF LEN(wate$) THEN EXIT DO
END IF
LOOP UNTIL inp$ = ""
PRINT "Goodbye!"
FUNCTION anaCode$ (wd$)
w$ = LOWER$(wd$)
DIM l(26) 'count letter frequecies
FOR i = 1 TO LEN(w$)
n = ASC(MID$(w$, i, 1)) - 96
'just letters here
IF n > 0 AND n < 27 THEN l(n) = l(n) + 1 ELSE anaCode$ = "": EXIT FUNCTION
NEXT
'form coded word
FOR i = 1 TO 26
b$ = b$ + STR$(l(i))
NEXT
anaCode$ = b$
END FUNCTION
output sample:
(Enter nothing to quit)
Enter a set of letters that might be a scrambled word: eimt
Search List: 100%
1 emit
2 item
3 mite
4 time
OK, that was the end of the search.
Press enter to continue, enter anything to quit...
PS used QB64 Editor to format and syntax check code (though some differences to JB).