I working on some functionality, on behalf of a teacher, that groups students into teams. To this end, I am looking for help to determine an efficient way of generating all possible team combinations that meet the following criteria:
- All students are represented in a team, and each student appears only once
- Teams have a maximum and minimum size
- There are a maximum number of teams
Example inputs:
students=['a','b','c','d','e','f','g','h','i','j']
max_team_size=5
min_team_size=2
max_team_count=4
Example of some desired output:
[['a','b','c','d'],['e','f','g'],['h','i','j']],
[['a','b','c'],['d','e','f','g'],['h','i','j']],
[['a','b','c'],['d','e','f'],['g','h','i','j']],
[['a','b'],['c','d','e'],['f''g','h'],['i','j']],
[['a','b','c','d','e'],['f''g','h','i','j']],
...
There are a bunch of other student/teacher preferences and such that will be used to filter
the results later, but for now, need some help generating all possible combinations of teams.
I've tried using [itertools.combinations
]1, but I haven't yet found the magic that fits my particular
situation (given my novice python and set theory skills). I've also come across similar,
over-my-head examples, which get me close, but are not quite what I'm after: