Click here to Skip to main content
15,913,939 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
if i have meatrix like this (3Xn )

if n=3 the number of combination need to be 3^n => 3^3 = 27
That is,27 diffrents matrix with 3Xn .

27 matrix like this :

a1|a2|a3
b1|b2|b3
c1|c2|c3


100 | 010 | 001 | 100 | and more....................... 27 matrix
100 | 100 | 100 | 010 |
100 | 100 | 100 | 100 |

i think it need to be Recursion.

please help me!! :(
Posted
Updated 20-Feb-15 1:38am
v2
Comments
BillWoodruff 20-Feb-15 8:33am    
Not clear if you want to generate a matrix in the mathematical sense where each intersection where row i == col i is a null, or zero, or if you want to generate some combinatorial form of all permutations.

Please clarify what the inputs and expected output are here.
BillWoodruff 20-Feb-15 9:51am    
Okay, that's clear. What have you tried so far, and why do you think this requires recursion ?
Member 10631195 20-Feb-15 9:58am    
ok i need or to loop x N

for(i=0;i<numberofgames; i++)
="" for(j="0;j<3" ;j++)
="" for(z="0" ;x<3="" ;x++)
="" for(q="0" ;q<3="" ;q++)
="" {=""
="" my="" list="new" list<int="">(); // once up
myList.add(0);
myList.add(1);
myList.add(2);

allForm.add(myList);

}

___________________________
the loop need to be 'n' time
BillWoodruff 20-Feb-15 10:05am    
Good. Is it the case that you want to enter a variable number of games to generate all the outome-combinations ? Do you know how to write the code for generating the three-game permutations (27 outcomes) ?
Member 10631195 20-Feb-15 10:06am    
no :(

1 solution

It appears you do know how to write the code for for a three-team three-game series, but you answered my question ... do you want to make your code flexible ... i.e., the number of teams can vary ? ... with "no." That's confusing.

If you want to make the number of teams variable, you need to implement a combination-creating solution, and that will probably be recursive.

CodeProject has seven articles on creating Permutations and Combinations in C#: [^]. I predict you will find usable code in those articles.

Here's an example of using the code in the first CodeProject article linked-to above, "Permutations, Combinations, and Variations using C# Generics" by Adrian Atkinson, to create the possible variations you describe:
C#
// required along with the source code from the article, and other usual references
using Facet.Combinatorics;

private List<string> outcomes = new List<string>{"Win", "Tie", "Lose"};
private List<List<string>> possibleOutcomes = new List<List<string>>(); 

private void button2_Click(object sender, EventArgs e)
{
    Variations<string> games = new Variations<string>(outcomes, 3, GenerateOption.WithRepetition);

    // get the result into a "concrete" List<List<string>>
    possibleOutcomes = games.Select(lst => lst.ToList()).ToList();

    // check the reults
    foreach (var game in possibleOutcomes)
    {
        Console.WriteLine(String.Format("{{{0} {1} {2}}}", game[0], game[1], game[2]));
    }
}
Also, I suggest you review the discussion and C# permutation-building strategies here: [^], to focus on what type of permutation-builder you want to implement, and get some ideas of the computational cost/speed/memory-use.
 
Share this answer
 
v4
Comments
Member 10631195 20-Feb-15 10:44am    
ok i take a look Thank you very much.

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