All possible combination of pairs + 1 triple group from an odd list?

Starting with an odd list of students, let’s say 21 total:

cohort = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] 

I want use Python to write a function that assign pairs for group projects every day with different pairings. Since we have an odd number of students, I don’t want anyone to be working alone, so we would need to have 9 groups of 2 people and 1 group of 3 people. Every day they would change partners. For example, on day 1 and day 2, the groups would look like this:

[(0, 1), (2, 3), (4, 5), (6, 7), (8, 9), (10, 11), (12, 13), (14, 15), (16, 17), (18, 19, 20)]
[(1, 2), (3, 4), (5, 6), (7, 8), (9, 10), (11, 12), (13, 14), (15, 16), (17, 18), (19, 20, 0)]

And so on. The order of the pairs isn’t important, so (0, 1) = (1, 0) and (0, 1, 2) = (2, 1, 0) = (1, 2, 0), etc.

How can I write a function in Python to print all possible configurations for the class pairings? I would like to see all the lists for each day and know how long it will take for everyone to work together at least once.

I looked into round robin scheduling algorithms and itertools.combinations, but haven't found a graceful solution for how to account for the final tuple of 3 created by the odd group number. I started writing the following function to get all possible two-people pairings from the following list, but I know this isn't quite going in the right direction, but I'm not sure how to proceed with making the list of groups (maybe they need to be unordered sets instead?) for each day…

def all_pairs(cohort):
    result = []
    for person1 in range(len(cohort)):
            for person2 in range(person1+1,len(cohort)):
                    result.append([cohort[person1],cohort[person2]])
    return result

pairings = all_pairs(cohort)
num_pairs = len(pairings)
print(f"{num_pairs} pairings")
for pair in pairings:
    print(pair)


from Recent Questions - Stack Overflow https://ift.tt/3okc6Dh
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)