# How can I figure out every permutation of sets of groups of four students in a class?

I'm trying to develop a grouping system that takes in a bunch of data for when particular students are available to meet and then spits out the "best" groups based on that data. Here I am defining best as the set of four-person groups which has the highest average number of matching hours per group.

The problem is, I don't know how to find every permutation of sets of four-person groups.

I started thinking: I could find every possible group of four... but a person can only be in one group. How about I find every possible group of four, and then I make a set of groups based on that starting group, where I only add groups who don't contain members already existing in the set.

I'm pretty confused. Any help getting me out of this hole would be greatly appreciated!

-

Not sure if this what you want but as I understand, you are trying to find group(s) of $4$ from a population of $N$ where the best group has the highest common/average availibility.
By taking $4$ persons each time, the total possible number of groups you can form is $\binom{N}{4}=\frac{N!}{4!\times(N-4)!}$. So, it is indeed possible to go through all of them and check for the ones with highest average.
Alternatively, you can create sub-sets $(N_1, N_2, N_3, ...)$ out of $N$ where, for example person $(p_1,p_3,p_{10},p_{15},p_{19}, ...)$ in $N_1$, has the common hour of availibility. Now, start with the sub-sets where the population is equal or more than $4$. Find best group(s) for each of $N_1, N_2, N_3, ...$. This should give you the overall best group.