-1

I am trying to find a way to iterate over all possible combinations of dividing 12 objects over equally sized 4 groups (order within the group doesn't matter, the order of the groups does matter).

I know the total amount of combinations is 369600 = 12! / (3!)^4, but I have no idea how I would go about iterating over all these different combinations.

Lrrr
  • 4,755
  • 5
  • 41
  • 63
  • 1
    Does this answer your question? [Generating all possible sets of 3 groups of 6 numbers chosen from the integers 1-18](https://stackoverflow.com/questions/64272107/generating-all-possible-sets-of-3-groups-of-6-numbers-chosen-from-the-integers-1) – Joseph Wood Nov 23 '20 at 20:42

1 Answers1

0

You have objects as O[0], ..., O[11] and groups as G[0], ..., G[3] now you could assign objects to groups with steps like this:

1.Select 3 object for G[0] like this:

for(i = 0 ; i<10 ; i++){
     for(j = i+1 ; j<11 ; j++){
         for(k = j+1 ; k<12 ; k++){
              G[0] = {O[i] , O[j] , O[k]}

2.Create a new object list by removing the O[i], O[j], O[k] from the object list and do the same thing like the pseudo-code above for G[1], I mean something like this:

for(l = 0 ; l<7 ; l++){
     for(m = l+1 ; m<8 ; m++){
         for(n = m+1 ; n<9 ; n++){
              G[1] = {O[l] , O[m] , O[n]}
  1. Do the same thing as step 2 for G[2]

  2. Assign the 3 remaining items to G[3]

  3. Write out G[1], G[2], G[3], G[4]

Lrrr
  • 4,755
  • 5
  • 41
  • 63