ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 8th, 2011, 10:15 PM
Samuelg78 Samuelg78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2010
Posts: 13 Samuelg78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old March 8th, 2011, 11:41 PM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
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.

Reply With Quote
  #3  
Old March 8th, 2011, 11:51 PM
Samuelg78 Samuelg78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2010
Posts: 13 Samuelg78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old March 9th, 2011, 08:29 AM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
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.

Reply With Quote
  #5  
Old March 9th, 2011, 11:24 AM
Samuelg78 Samuelg78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2010
Posts: 13 Samuelg78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #6  
Old March 9th, 2011, 06:32 PM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
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.

Reply With Quote
  #7  
Old March 9th, 2011, 09:16 PM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
Also, out of curiosity, what do you want to do with this? It doesn't seem very useful.

Reply With Quote
  #8  
Old March 9th, 2011, 11:22 PM
Samuelg78 Samuelg78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2010
Posts: 13 Samuelg78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #9  
Old March 10th, 2011, 12:37 PM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
I see. Well, like I said, the link above outlines the logical approach for the recursive combination algorithm.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Coldfusion String return combinations

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap