The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> ColdFusion Development
|
Coldfusion String return combinations
Discuss Coldfusion String return combinations in the ColdFusion Development forum on Dev Shed. Coldfusion String return combinations ColdFusion Development forum discussing CFML coding practices, tips on CFML, and other CFML related topics. Find out why ColdFusion is the tool of choice for many e-commerce developers.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 8th, 2011, 10:15 PM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 13
Time spent in forums: 41 m 41 sec
Reputation Power: 0
|
|
|
Coldfusion String return combinations
I will like to return a table/list of rows consist of all possible combination of a string. For example string "01-02-03-04":
1. 01 - 02 - 03 - 04
2. 02 - 03 - 04
3. 01 - 03 - 04
4. 01 - 02 - 04
5. 01 - 02 - 03
6. 01 - 02
7. 01 - 03
8. 01 - 04
9. 02 - 03
10. 02 - 04
11. 03 - 04
Any help will be much appreciated. Thks in advance.
|

March 8th, 2011, 11:41 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
I did it like this:
Code:
<cfscript>
delimiter = "-";
results = [];
values = "01-02-03-04";
valueArray = ListToArray( values, delimiter );
for( i=1; i <= ArrayLen( valueArray ); i++ )
{
currentValue = valueArray[i];
ArrayAppend( results, currentValue );
for( j=1; j <= ArrayLen( valueArray ); j++ )
{
if( valueArray[i] != valueArray[j] )
{
currentValue = currentValue & delimiter & valueArray[j];
ArrayAppend( results, currentValue );
}
}
}
WriteDump( results );
</cfscript>
Which dumps the array of all of the permutations:
Code:
array
1 01
2 01-02
3 01-02-03
4 01-02-03-04
5 02
6 02-01
7 02-01-03
8 02-01-03-04
9 03
10 03-01
11 03-01-02
12 03-01-02-04
13 04
14 04-01
15 04-01-02
16 04-01-02-03
Last edited by kiteless : March 8th, 2011 at 11:45 PM.
|

March 8th, 2011, 11:51 PM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 13
Time spent in forums: 41 m 41 sec
Reputation Power: 0
|
|
|
Your result is different from mine. Pls take note that
"01-02-03-04" is the same as "02-01-03-04" which is redundant.
1 01
2 01-02
3 01-02-03
4 01-02-03-04
5 02
6 02-01
7 02-01-03
8 02-01-03-04
9 03
10 03-01
11 03-01-02
12 03-01-02-04
13 04
14 04-01
15 04-01-02
16 04-01-02-03
|

March 9th, 2011, 08:29 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
Er, you said you wanted all possible combinations of a string. "01-02-03-04" is NOT the same as "02-01-03-04". That's like saying "ABCD" is the same as "BACD". Which clearly it is not.
If what I showed isn't exactly what you want, feel free to modify it to suit your purposes.
|

March 9th, 2011, 11:24 AM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 13
Time spent in forums: 41 m 41 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by kiteless Er, you said you wanted all possible combinations of a string. "01-02-03-04" is NOT the same as "02-01-03-04". That's like saying "ABCD" is the same as "BACD". Which clearly it is not.
If what I showed isn't exactly what you want, feel free to modify it to suit your purposes. |
Forgive me if my description is not clear. Actually for "01-02-03-04", i only wanted the results as shown above. 
|

March 9th, 2011, 06:32 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
In that case you're going to want to take a recursive approach instead. I'd use something like this as a starting point for the logical flow.
|

March 9th, 2011, 09:16 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
Also, out of curiosity, what do you want to do with this? It doesn't seem very useful.
|

March 9th, 2011, 11:22 PM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 13
Time spent in forums: 41 m 41 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by kiteless Also, out of curiosity, what do you want to do with this? It doesn't seem very useful. |
Actually i need to do it cos my company is awarded a project with some overseas lottery company. And i had been assigned to this project. 
|

March 10th, 2011, 12:37 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
I see. Well, like I said, the link above outlines the logical approach for the recursive combination algorithm.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|