I'd make some changes to make it easier to read.  First, instead of
wordarray[arraylen(wordarray)+1] = ...

I'd use arrayappend().

Second, if you aren't going to use ccArr, sbArr, and rcArr, remove them 
from the function.  They are just confusing.

If the length of remainingchars is 1, you don't need the mid() function.

You don't need mid() later, either.  You can use left and right, which 
might be less confusing.

You are returning an array, and trying to insert it into a single array 
element.  I think you're getting nested arrays.  Try dumping the entire 
argument scope (including wordarray) before returning on each recursion.

HTH.

--Ben Doom

Greg Morphis wrote:
> I thought I had it with this.. which is similiar to what you suggested Ben
> 
> <cffunction name="createWordList" returntype="array">
>       <cfargument name="wordArray" required="yes" type="array" />
>       <cfargument name="strbase" default="" required="yes" type="string" />
>       <cfargument name="remainingchars" default="" required="yes" 
> type="string" />
>       
>       <cfset var j = 1 />
>       <cfset var currchar = "" />
>       <cfset ccArr = arraynew(1) />
>       <cfset sbArr = arraynew(1) />
>       <cfset rcArr = arraynew(1) />
> 
>       <cfscript>
>       if(len(remainingchars) eq 1) {
>               wordArray[ArrayLen(wordArray)+1] = strbase & 
> mid(remainingchars,1,1);
>       } else {
>               for (j = 1; j lt len(remainingchars); j=j+1) {
>                       currchar = mid(remainingchars,j,1);
>                       if(find(currchar,remainingchars,j) eq j) {
>                               wordArray[ArrayLen(wordArray)+1] = 
> createWordList(wordArray,
> mid(remainingchars,1,j) &
> mid(remainingchars,j+1,len(remainingchars)));
> 
>                               }
>               }
>       }
>               
>       </cfscript>
> <cfreturn wordArray />
> </cffunction>
> 
> 
> But all I get is an empty Array.. :
> array
> 1     
> array [empty]
> 2     
> array
> 1     
> array [empty]
> 3     
> array
> 1     
> array [empty]
> 2     
> array
> 1     
> array [empty]
> 
> 
> 
> On Thu, Feb 14, 2008 at 8:30 AM, Ben Doom <[EMAIL PROTECTED]> wrote:
>> In pseudocode:
>>
>>  function f(sofar, more)
>>  {
>>         array strings
>>         foreach letter in more
>>         {
>>                 strings = f(foreach+letter, more-letter)
>>         }
>>         return strings
>>  }
>>
>>  HTH.
>>
>>  --Ben Doom
>>
>>
>>
>>  Greg Morphis wrote:
>>  > anyone else? I was hoping to do this in CF alone?
>>  >
>>  > Thanks
>>  >
>>  > On Wed, Feb 13, 2008 at 6:59 PM, Dawson, Michael <[EMAIL PROTECTED]> 
>> wrote:
>>  >> Thinking outside the box...  You could use a database for this.  Create 
>> a table that contains a single column.  That column contains a record for 
>> each letter of the alphabet.  Then, do a cartesian join to join that table 
>> to itself, three other times.  Concatenate the fields and you should have 
>> each combination.
>>  >>
>>  >> That would get the first part without consideration of the second part.
>>  >>
>>  >> m!ke
>>  >>
>>  >>  _____
>>  >>
>>  >> From: Greg Morphis [mailto:[EMAIL PROTECTED]
>>  >> Sent: Wed 2/13/2008 4:57 PM
>>  >> To: CF-Talk
>>  >> Subject: all possible letter combinations
>>  >>
>>  >>
>>  >>
>>  >>
>>  >> Given a string, e.g. "ABCD"
>>  >>
>>  >> I need to come up with all combinations of letters
>>  >> eg
>>  >> ABCD
>>  >> ABDC
>>  >> ACBD
>>  >> ACDB
>>  >> .....
>>  >>
>>  >> And exlude strings like 'AAAA', 'AAAB' unless you pass a string with
>>  >> duplicate characters
>>  >> If I pass the string "AAAB" then it'd return:
>>  >> AAAB
>>  >> AABA
>>  >> ABAA
>>  >> BAAA
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >
>>  >
>>
>>  
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:299005
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to