Generates a list of possible combos for a given string. Limit can be set on minimum word length.
Version 1.1 adds speed improvements for duplicates
--adds min and max characters
on getAllCombos whatText, minChars, maxChars
if maxChars = void then maxChars = the maxInteger
if minChars = void then minChars = the maxInteger
--create a list of characters
charList = []
repeat with x = 1 to whatText.char.count
charList.add(whatText.char[x])
end repeat
sort charList
--create an empty list of words...
wordList = []
--start with an empty string
baseString = ""
--find all combos
createAllCombos(baseString, charList, wordList, minChars, maxChars)
--sort it
-- sort(wordList)
return wordList
end
on createAllCombos baseString, charList, wordList, minChars, maxChars
--use each letter
if baseString.char.count < maxChars then
c = ""
repeat with x = 1 to charList.count
--if its the same as the last letter we will get duplicates so skip it
if c = charList[x] then next repeat
c = charList[x]
--get the new string
newString = baseString & c
--add the current combo
if newString.char.count >= minChars then wordList.append(newString, wordlist.count)
--find the new words with recursion -- use a duplicate as lists are referenced
newCharList = charList.duplicate()
newCharList.deleteAt(x)
if newCharList.count > 0 then
createAllCombos(newString, newCharList, wordList, minChars, maxChars)
end if
end repeat
end if
end
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA