Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
girmalemu #1
Possible combinations
I have two lists: (A ) and (1,2,3). I need all possible combination of the two
lists: Is there any way to loop throgh these combinations; A1, A2, A3, A12,
A13,....... etc
Any help is very appreciable.
girmalemu Guest
-
digital combinations
What digital combination is the equivalent to a 35mm with a 80 to 200 zoom lens. -
combinations
"David Byrne" <dbyrne_commerce@yahoo.com> wrote in message news:20030804204911.18868.qmail@web40706.mail.yahoo.com... Hi David. This should do... -
mxstu #2
Re: Possible combinations
Something like this maybe? Arrays might be more efficient though.
<cfset allCombinations = "">
<cfset listOne = "A,B">
<cfset listTwo = "1,2,3,12,13">
<cfloop from="1" to="#listLen(listOne)#" index="x">
<cfset outerValue = listGetAt(listOne, x)>
<cfloop from="1" to="#listLen(listTwo)#" index="y">
<cfset innerValue = listGetAt(listTwo, y)>
<cfset allCombinations = listAppend(allCombinations, outerValue & innerValue)>
</cfloop>
</cfloop>
<cfoutput>
#allCombinations#
</cfoutput>
mxstu Guest
-
johnclef #3
Re: Possible combinations
Thanx mxstu,
I have also the same question in possible combinations of A with all numbers
and all numbers themselves. Say I have (A ) and (1,2,3). Thus A, A-1, A-2,
A-3, 1-1, 1-2, 1-3, 2-3.
Thank you again
johnclef Guest
-
-
-
mxstu #6
Re: Possible combinations
Something like this.... Note - I wouldn't use it for large lists because the
total number of loops is the (number of elements in the list ^ 2). So if your
second list contained 100 elements, CF will loop 10,000 times.
<cfset listOne = "A">
<cfset listTwo = "1,2,3">
<cfset allCombinations = "">
<!--- get letter number combinations --->
<cfloop from="1" to="#listLen(listOne)#" index="x">
<cfset outerValue = listGetAt(listOne, x)>
<cfset allCombinations = listAppend(allCombinations, outerValue)>
<cfloop from="1" to="#listLen(listTwo)#" index="y">
<cfset innerValue = listGetAt(listTwo, y)>
<cfset allCombinations = listAppend(allCombinations, outerValue &"-"&
innerValue)>
</cfloop>
</cfloop>
<cfloop from="1" to="#listLen(listTwo)#" index="x">
<cfset outerValue = listGetAt(listTwo, x)>
<cfloop from="1" to="#listLen(listTwo)#" index="y">
<cfset innerValue = listGetAt(listTwo, y)>
<cfset allCombinations = listAppend(allCombinations, outerValue &"-"&
innerValue)>
</cfloop>
</cfloop>
<cfoutput>
#allCombinations#
</cfoutput>
mxstu Guest
-
johnclef #7
Re: Possible combinations
mxstu,
IT WORKS, THAT WAS GR8! IT IS EXACTLY WHAT I NEEDED.
Thank you a lot.
johnclef Guest
-
girmalemu #8
Re: Possible combinations
What about A-1-1, A-1-2, A-1-3, A-2-1,A-2-2,A-2-3,A-3-1,A-3-2,A-3-3, A-1-2-3, ...................?
girmalemu Guest
-
girmalemu #9
Re: Possible combinations
<cfset listOne = "A">
<cfset listTwo = "1,2,3">
<cfset allCombinations = "">
<!--- get letter number combinations --->
<cfloop from="1" to="#listLen(listOne)#" index="x">
<cfset outerValue = listGetAt(listOne, x)>
<cfset allCombinations = listAppend(allCombinations, outerValue)>
<cfloop from="1" to="#listLen(listTwo)#" index="y">
<cfset innerValue = listGetAt(listTwo, y)>
<cfset allCombinations = listAppend(allCombinations, outerValue &"-"&
innerValue)>
</cfloop>
</cfloop>
<cfloop from="1" to="#listLen(allCombinations)#" index="x">
<cfset outerValue = listGetAt(allCombinations, x)>
<cfloop from="1" to="#listLen(listTwo)#" index="y">
<cfset innerValue = listGetAt(listTwo, y)>
<cfset allCombinations = listAppend(allCombinations, outerValue &"-"&
innerValue)>
</cfloop>
</cfloop>
<cfoutput>
#allCombinations#
</cfoutput>
Loop through allCombinations to get all the combinations ut redundant.
A
A-1
A-2
A-3
A-1
A-2
A-3
A-1-1
A-1-2
A-1-3
A-2-1
A-2-2
A-2-3
A-3-1
A-3-2
A-3-3
What I want is:
A
A-1
A-2
A-3
A-1-2
A-1-3
A-2-3
girmalemu Guest
-
mxstu #10
Re: Possible combinations
girmalemu,
That last example was in reponse to johnclef's question. I believe he needs
something slightly different than what you orginally requested, which is:
I have two lists: (A ) and (1,2,3). I need all possible combination of the two
lists: Is there any way to loop throgh these combinations; A1, A2, A3, A12,
A13,....... etc
Are you now looking for something different?
mxstu Guest
-
girmalemu #11
Re: Possible combinations
Originally posted by: mxstu
girmalemu,
That last example was in reponse to johnclef's question. I believe he needs
something slightly different than what you orginally requested, which is:
I have two lists: (A ) and (1,2,3). I need all possible combination of the two
lists: Is there any way to loop throgh these combinations; A1, A2, A3, A12,
A13,....... etc
Are you now looking for something different?
Yes, What I want is:
A
A-1
A-2
A-3
A-1-2
A-1-3
A-2-3
girmalemu Guest
-
mxstu #12
Re: Possible combinations
girmalemu,
You should be able to do this by adding another loop. I adjusted the code to
use the technique mentioned by Neculai on your other thread. It is cleaner.
Note - As mentioned before, this would not be suitable for large lists, due to
the total number of loops required.
<cfset allCombinations = "">
<cfset listOne = "A">
<cfset listTwo = "1,2,3">
<cfloop list="#listOne#" index="x">
<cfset allCombinations = listAppend(allCombinations, x)>
<cfloop list="#listTwo#" index="y">
<cfset allCombinations = listAppend(allCombinations, x &"-"& y )>
<cfloop list="#listTwo#" index="z">
<cfset allCombinations = listAppend(allCombinations, x &"-"& y &"-"& z )>
</cfloop>
</cfloop>
</cfloop>
<cfoutput>
#allCombinations#
</cfoutput>
mxstu Guest
-
girmalemu #13
Re: Possible combinations
Mxstu,
Thank you for the propmt reply. But
<cfset listOne = "A">
<cfset listTwo = "1,2">
gives me:
A
A-1
A-1-1
A-1-2
A-2
A-2-1
A-2-2
What I need is:
A
A-1
A-2
A-1-2
The rest of the combination is redundant.
Thanx!
girmalemu Guest
-
girmalemu #14
Re: Possible combinations
Originally posted by: mxstu
girmalemu,
You should be able to do this by adding another loop. I adjusted the code to
use the technique mentioned by Neculai on your other thread. It is cleaner.
Although you may have to sort it if you want the elements in the same order you
mentioned.
Note - As mentioned before, this would not be suitable for large lists, due to
the total number of loops required.
Mxstu,
Thank you for the propmt reply. But
<cfset listOne = "A">
<cfset listTwo = "1,2,n">
gives me:
A
A-1
A-1-1
A-1-2
A-2
A-2-1
A-2-2
What I need is:
A
A-1
A-2
A-1-2
A-1-2-n
Thanx!
girmalemu Guest
-
mxstu #15
Re: Possible combinations
What I need is:
A
A-1
A-2
A-1-2
A-1-2-n
I'm really not sure what the logic here is. Once you define your rules for
what values you want returned it should be simple to modify the sample code to
achieve that.
mxstu Guest
-
girmalemu #16
Re: Possible combinations
Originally posted by: mxstu
girmalemu,
You should be able to do this by adding another loop. I adjusted the code to
use the technique mentioned by Neculai on your other thread. It is cleaner.
Although you may have to sort it if you want the elements in the same order you
mentioned.
Note - As mentioned before, this would not be suitable for large lists, due to
the total number of loops required.
Mxstu,
Thank you very much for your propmt reply. But
<cfset listOne = "A">
<cfset listTwo = "1,2">
Produces:
A
A-1
A-1-1
A-1-2
A-2
A-2-1
A-2-2
Here is the situation:
<cfset listOne = "A,[n]">
<cfset listTwo = "1,2,[n]">
The lists are dynamic, [n] ranges from 1 to 12.
What I need is:
A
A-1
A-2
A-[n]
A-1-2
A-1-2-[n]
Thanks a lot for your help!
girmalemu Guest



Reply With Quote

