Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
Hi all,

I need to find combinations, and calculate values for the resultant combinations by substituting values..

C#
string[] str=new string[]{"A","B","C","D"};
double[] vals=new double[]{1,3,6,9};

A=1;
B=3;
C=6;
D=9

Say N=4,M=3;// N and M are Dynamic values
N-M+1=2;

so i want to find combinations for str with N-M+1 Value ie 4C2 = 6.
i am getting 6 Combinations.
AB
AC
AD
BC
BD
CD..

finally i want to calculate & store the combination values in another Array..

I used below code, it works for N=4,M=2
for (int j = 0; j < factval; j++)//factval,faval is FactorialValue ie 4C3 Combination Value
{
   for (int k = 0; k < PFDdu.Length; k++)//PFDdu is str Length
   {
       if (!string.IsNullOrEmpty(PFDdu[(k + 1) % PFDdu.Length].ToString()))
       {
          if (j != (k + 1) % PFDdu.Length)
          {
              faval[j] = faval[j] * PFDdu[(k + 1) % PFDdu.Length];
          }
       }
   }
}



Can any body help me on this plz..

with Regards,
Pawan.
Posted
Updated 2-Mar-11 4:21am
v3

1 solution

Does this help?
Combinatorial algorithms in C#[^]

What about this one?
Permutations, Combinations, and Variations using C# Generics[^]

Search on google, I am sure you will find.
 
Share this answer
 
v2
Comments
Pawan Kiran 2-Mar-11 9:53am    
it doesn't help me to overcome my issue..
Olivier Levrey 2-Mar-11 10:07am    
Added another one...
Pawan Kiran 2-Mar-11 12:01pm    
vote of 5..
solves my issue.. thank u very much..
Olivier Levrey 2-Mar-11 12:10pm    
you're welcome ;)
you may also click the "accept answer" button to show it is solved.
Sergey Alexandrovich Kryukov 2-Mar-11 13:04pm    
Pawan, do accept Olivier's Answer, it's good.
My 5, too.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900