Try this chunk of code. I leave it up to you to add in a remove duplicates
feature. Check cflib.org for some handy functions to do that.
NOTE: I found it easier to build a list instead of an array simply because I
could recurse with ListAppend but if I recurse with ArrayAppend it starts
making a mess and then I'm mixing return types and other nasty stuff. So, I
just created a helper to call ListToArray. :)
<cffunction name="createWordArray" returntype="array">
<cfargument name="dictionary" type="string" required="true">
<cfreturn ListToArray(createWords("", dictionary))>
</cffunction>
<cffunction name="createWords" returntype="string" output="true">
<cfargument name="word" type="String" required="true">
<cfargument name="dictionary" type="String" required="true">
<cfset var aList="">
<cfset var newWord = "">
<cfset var newDict = "">
<cfif Len(dictionary) EQ 1>
<cfset newWord = word & dictionary>
<cfreturn newWord>
</cfif>
<cfloop from="1" to="#Len(dictionary)#" index="myChar">
<cfset newWord = word & Mid(dictionary,myChar,1)>
<cfset newDict = RemoveChars(dictionary,myChar,1)>
<cfset aList = ListAppend(aList,createWords(newWord, newDict))>
</cfloop>
<cfreturn aList>
</cffunction>
<cfset chars = "abcd">
<cfset myWordArray = createWordArray(chars)>
<cfdump var="#myWordArray#">
<cfset chars = "aaab">
<cfset myWordArray = createWordArray(chars)>
<cfdump var="#myWordArray#">
>Given a string, e.g. "ABCD"
>
>I need to come up with all combinations of letters
>eg
>ABCD
>ABDC
>ACBD
>ACDB
>...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:299020
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4