Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Label Search code
Magic Button
Josh Chunick's Personal Site
Set Quality of a Flash Cast member
Moving MIAWs with lingo
Ripple Follow Mouse on Rollover-Alphamania
Create Icon
Back Button - All In One
Drag&Drop Xtra
Check Acrobat Version
 

 

 

Behavior Get all combinations of a string

Added on 5/29/2003

 

Compatibilities:
D7 D8 D8_5 D9 Mac PC Shockwave

This item has not yet been rated

Author: MediaMacros (website)

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

Send e-mail