# recursive team combinations

#### lovekeiiiy

##### Member
I need some help. Have an homework assignment where you're suppose to print all possible combinations of a teams of a given size that can be formed group of another size. The assignment is done in a console application.

I understand the gist of the problem. I don't really understand the mathematical formula given in the book: (n, k) = (n ? 1, k ? 1) + (n ? 1, k) k=size of team, n=size of group. I do get overall what it's doing. I found algorithm for the formula that works and finds the number of combinations.

What I was trying to do is create use a list of integers to represent the members of the group. Then have recursive method find the combinations for print the teams. I can't figure out how to print the teams.

recursive method
C#:
`````` //finds and displays all possible teams from given group size, and team size        public static void showTeams(int groupSize, int teamSize, string team)
{
//alogrith help/guide from:  https://www.gidforums.com/t-26253.html
//(n, k) = (n ? 1, k ? 1) + (n ? 1, k) k=size of team, n=size of group (forumal from class textbook)

//local variables

//base case:  team size is 0
if(teamSize == 0)
{
//team += groupMembers[groupSize].ToString() + " ";
//Console.WriteLine("team = " + team);
intTeamCounter++;
return;
}
//base case two:  team size is larger than group size
else if (groupSize < teamSize)
{
//can't have team larger than group.
return;
}
else
{
// team += groupMembers[groupSize - 1].ToString() + " ";

//reduce group size by one, and team size by one
showTeams(groupSize-1,teamSize-1, team);

showTeams(groupSize-1, teamSize, team);

}
}``````

main method
C#:
``````...[code removed]...
//create group list            groupMembers = new int[intSizeOfGroup];
for(int x = 0; x < intSizeOfGroup; x++)
{
groupMembers[x] = (x + 1);
}

string team= "";
//find all team combines and display
showTeams(intSizeOfGroup, intSizeOfTeam, team);

//display number of teams found
Console.WriteLine("The number of team combinations is " + intTeamCounter);``````

the other code in main is getting team and group size from the user and call methods to validate user input.

Replies
6
Views
1K
Replies
6
Views
890
Replies
11
Views
661
Replies
3
Views
338
Replies
1
Views
707