RE: all possible letter combinations
Actually, permutation is your friend... and there are tons of code samples and algorithms out there. I'd start here. http://www.google.com/search?hl=en&client=firefox-a&channel=s&rls=org.mozill a%3Aen-US%3Aofficial&hs=mXk&q=permutation+coldfusion&btnG=Search ..:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com > Recursion is your friend ;o) > > Mark > > On Feb 14, 2008 9:57 AM, Greg Morphis <[EMAIL PROTECTED]> wrote: > > > 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 '', '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:299028 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: all possible letter combinations
Hey that's pretty smooth. I appreciate it!! On Thu, Feb 14, 2008 at 1:27 PM, Jeff Price <[EMAIL PROTECTED]> wrote: > 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. :) > > > > > > > > > > > > > > > > > > > > > > > > > newDict))> > > > > > > > > > > > > > > > > > > >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:299021 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: all possible letter combinations
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. :) >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
Re: all possible letter combinations
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 > > > > >type="string" /> > > > > > > > > > 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))); > > } > } > } > > > > > > > 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 '', '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
Re: all possible letter combinations
I thought I had it with this.. which is similiar to what you suggested Ben 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))); } } } 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 '', '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:298998 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: all possible letter combinations
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 '', '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:298992 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: all possible letter combinations
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 '', '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:298990 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: all possible letter combinations
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 '', '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:298941 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: all possible letter combinations
This is what I have so far.. 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) { arrayappend(wordArray, mid(remainingchars,1,j) & mid(remainingchars,j+1,len(remainingchars))); //createWordList(wordArray, strbase & mid(remainingchars,1,j), mid(remainingchars,1,j) & mid(remainingchars,j+1,len(remainingchars))); //wordArray = createWordList(wordArray, strbase + remainingchars.charAt(j), remainingchars.substring(0, j) + remainingchars.substring(j+1, remainingchars.length)); //recursive call } } } The specific part I'm having problems with is //wordArray = createWordList(wordArray, strbase + remainingchars.charAt(j), remainingchars.substring(0, j) + remainingchars.substring(j+1, remainingchars.length)); //recursive call That's how it's done in Javascript.. I just can't convert it to ColdFusion.. On Feb 13, 2008 6:44 PM, Mark Mandel <[EMAIL PROTECTED]> wrote: > What have you got so far? > > Mark > > On Feb 14, 2008 10:58 AM, Greg Morphis <[EMAIL PROTECTED]> wrote: > > yes, I know that and it's that part that I need help with which is why > > I posted here. > > Thanks > > > > On Feb 13, 2008 5:34 PM, Mark Mandel <[EMAIL PROTECTED]> wrote: > > > Recursion is your friend ;o) > > > > > > Mark > > > > > > > > > On Feb 14, 2008 9:57 AM, Greg Morphis <[EMAIL PROTECTED]> wrote: > > > > 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 '', '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:298940 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: all possible letter combinations
What have you got so far? Mark On Feb 14, 2008 10:58 AM, Greg Morphis <[EMAIL PROTECTED]> wrote: > yes, I know that and it's that part that I need help with which is why > I posted here. > Thanks > > On Feb 13, 2008 5:34 PM, Mark Mandel <[EMAIL PROTECTED]> wrote: > > Recursion is your friend ;o) > > > > Mark > > > > > > On Feb 14, 2008 9:57 AM, Greg Morphis <[EMAIL PROTECTED]> wrote: > > > 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 '', '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:298939 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: all possible letter combinations
yes, I know that and it's that part that I need help with which is why I posted here. Thanks On Feb 13, 2008 5:34 PM, Mark Mandel <[EMAIL PROTECTED]> wrote: > Recursion is your friend ;o) > > Mark > > > On Feb 14, 2008 9:57 AM, Greg Morphis <[EMAIL PROTECTED]> wrote: > > 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 '', '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:298931 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: all possible letter combinations
Recursion is your friend ;o) Mark On Feb 14, 2008 9:57 AM, Greg Morphis <[EMAIL PROTECTED]> wrote: > 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 '', '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:298929 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
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 '', '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:298923 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4