Hacker News new | past | comments | ask | show | jobs | submit login
Creating Serendipity with Python (cloudflare.com)
30 points by weinzierl 52 days ago | hide | past | favorite | 23 comments



As cool as they look when you write them, comprehensions this dense obfuscate your code. Splitting this into multiple lines helps, but it would be much easier to understand as a normal for loop.

If the goal is to just know the number of items in each slot, here is the first thing that came to my mind (and does not require any iteration):

    groups = [n // g + n % g] + [n // g] * (g - 1)


Agreed. Don't see where iteration would be needed here if knowing group size is the actual goal.

It looks like a blog post that arrives at "this is essentially what the modulo operator does for you", but with an O(n) algorithm.

However, add a step inside that iterative loop that chooses, at random and without repeats, the actual named employees that will be in these meetings (which I believe will be the point), and none of this matters anyway, since you will wind up with something that is worse than O(n) anyway. You intrinsically have to iterate over the entire list and then, somehow, also choose employees at random, which cannot be "free" in computational terms.


The author wants leftovers to be evenly distributed. For example for n=15 and g=4 he wants [5,5,5].

I think his very first 3 liner is the most readable version. If we're microoptimizing, his comprehension version also has a lot of extra divisions. I would write something like this instead:

    q1, r1 = divmod(n, g)
    q2, r2 = divmod(r1, q1)
    print(n, [g + q2 + 1] * r2 + [g + q2] * (q1 - r2))


I missed the evenly distributed part; good point and good solution.


That's nice.


At the bottom of the Python doc page for itertools are “more itertools” in which the functions “grouper” and “roundrobin” seem to do the trick. Overkill?

Usage:

``` queues = grouper(names, minimum_number) serendipity_teams = roundrobin(queues) ```


> * groups = [0] * (n//g)

> * for i in range(n):

> * groups[i % len(groups)] += 1

this is obvious

> * groups = [1+max(0,n-(i+1))//(n//g) for i in range(n//g)]

this is not


Ignoring the code and technical aspects of the article, was the whole point of this just to add yet more meetings to people’s busy days?


I understood it to be a way to help employees feel connected to their coworkers in a way similar to what would happen naturally in an office setting. Many of us struggle with this.


    [n//(n//g)+(i<n%g) for i in range(n//g)]
Each one of (n//g) groups gets at least n//(n//g) members plus 1 if the remainder is >i.


Yeah, readability is far more important than elegance in the long run.


a solution with fewer lines is not always a simpler solution


It was great reading this to a 9 year old, thanks. We did come up with a solution easier to understand.


Setting up of SkypeForBusiness, Zoom, Teams, Webex conferences based on that and on times that are coordiated with the users calendars - THAT would be awesome.

It woud be a true serendipity experience - meeting people in your company you do not know.

I will have to discuss this tomorrow with HR.


If you want to assign people to groups randomly, why not just something like:

  import random
  import numpy

  people = [...]
  min_size = 3

  random.shuffle(people)
  groupings = numpy.array_split(people,len(people)//min_size)


Correcte if I'm wrong but the post was about determining the number of groups and their size, not actually assigning people to them.


The article starts with "We've been experimenting with breaking up employees into random groups (of size 4)." How does stopping at a list of group sizes (numbers) help you do that?


Idk but that's what the article did


What is notable here?


I generally find the Cloudflare blog posts interesting and entertaining but this one seems more suitable for a personal blog.


Wholly agreed. It seems like the bar of a quality post was lowered significantly for the CTO...


Oh man. Take a chill pill. We've got a ton more meaty posts coming, just skip this light one, have a good Saturday. We've got "comparison of different ARM processors", "detailed look at how executables work", "benefits of stale DNS with Consul", an analyst report and a series on designing our Teams product.

Can't wait? Read this instead: https://blog.cloudflare.com/cloudflare-workers-now-support-c...

I actually wrote that post because the internal blog pipeline at Cloudflare had dried up. By posting it and cajoling people I managed to get a whole load of posts to appear (I bet some of those people were thinking "I can do better than THAT!")


Well, I for one enjoyed it.

This problem has a name actually - there’s a solution called Bjorklund’s algorithm which was originally used in physics. It was picked up by a music researcher (Godfried Toussaint) who noticed that it generates satisfying rhythms too. https://en.m.wikipedia.org/wiki/Euclidean_rhythm I implemented it myself for Sonic Pi as the spread function.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: