[HN Gopher] Creating Serendipity with Python
___________________________________________________________________
Creating Serendipity with Python
Author : weinzierl
Score : 28 points
Date : 2021-02-26 08:25 UTC (1 days ago)
(HTM) web link (blog.cloudflare.com)
(TXT) w3m dump (blog.cloudflare.com)
| BrandoElFollito wrote:
| 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.
| css wrote:
| 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)
| uyt wrote:
| 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))
| css wrote:
| I missed the evenly distributed part; good point and good
| solution.
| jgrahamc wrote:
| That's nice.
| llarsson wrote:
| 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.
| Vaslo wrote:
| 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?
| oburb wrote:
| a solution with fewer lines is not always a simpler solution
| blueicecubes wrote:
| 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)
| kowlo wrote:
| > * 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
| [deleted]
| pyyp wrote:
| [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.
| glare10 wrote:
| What is notable here?
| majormjr wrote:
| I generally find the Cloudflare blog posts interesting and
| entertaining but this one seems more suitable for a personal
| blog.
| usrme wrote:
| Wholly agreed. It seems like the bar of a quality post was
| lowered significantly for the CTO...
| jgrahamc wrote:
| 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!")
| xavriley wrote:
| 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.
| tartakovsky wrote:
| 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) ```
| lvass wrote:
| It was great reading this to a 9 year old, thanks. We did come up
| with a solution easier to understand.
| dfilppi wrote:
| Yeah, readability is far more important than elegance in the long
| run.
___________________________________________________________________
(page generated 2021-02-27 23:02 UTC)