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
If you ever look at pictures of clocks and watches in advertising they are set to roughly 10:10 which is meant to be the most attractive (smiling!) position for the hands . They are actually set to 10:09.14 if the hands are truly symmetrical. CC BY 2.0 image by Shinji I wanted to know what all the possible symmetrical watch faces are and so I wrote some code using Processing. Here's the output (there's one watch face missing, 00:00 or 12:00, because it's very boring): The key to writing this is to figure out the relationship between the hour and minute hands when the watch face is symmetrical. In an hour the minute hand moves through 360° and the hour hand moves through 30° (12 hours are shown on the watch face and 360/12 = 30). The core loop inside the program is this: for (int h = 0; h <= 12; h++) { float m = (360-30*float(h))*2/13; int s = round(60*(m-floor(m))); int col = h%6; int row = floor(h/6); draw_clock((r+f)*(2*col+1), (r+f)*(row*2+1),