Skip to main content

Posts

Showing posts from January, 2021

Dividing n elements into groups of at least size g minimizing the size of each group

At work there's a little project to break up groups of employees into random groups (size 4) and set up Zoom calls between them. We're doing this to replace the serendipitous meetings that sometimes occur around coffee machines, in lunch lines or while waiting for the printer. And also, we just want people to get to know each other. Which lead to me writing some code. The core of which is 'divide n elements into groups of at least size g minimizing the size of each group'. So, suppose an office has 15 employees in it then it would be divided into three groups of sizes 5, 5, 5; if an office had 16 employees it would be 4, 4, 4, 4; if it had 17 employees it would be 4, 4, 4, 5 and so on. I initially wrote the following code (in Python):     groups = [g] * (n//g)     for e in range(0, n % g):         groups[e % len(groups)] += 1 The first line creates n//g  ( // is integer division) entries of size g (for example, if g == 4 and n == 17 then groups == [4, 4, 4, 4] ). Th