by qsort on 5/18/2025, 10:09:54 AM
by giomasce on 5/18/2025, 10:47:07 AM
What Every Programmer Should Know About Enumerative Combinatorics -> Nothing.
It can be interesting to know something (or even a lot) about enumerative combinatorics, and certainly there are some specific programming contexts in which that's a hard prerequisite, but it's not a topic that necessarily concerns every programmer.
OTOH I think it would greatly help programmers, especially beginners, to have fewer click baity titles around.
by simpaticoder on 5/18/2025, 2:27:51 PM
This has the flavor of a post written by a programmer who got a particularly interesting interview question. They continued working on it when they got home. Hey, it's happened to the best of us (I was once asked to write "tic tac toe" and at the time I was really getting into functional programming and simple data structures, and for some reason I didn't stop working on the problem for a few days because I wanted to generalize tic-tac-toe in scale, depth, e.g. deeply nested tic-tac-toe, and dimension, where the board has more than 2 dimensions) but I'm not sure I would have written a paper "What every programmer should know about implementing nested tic-tac-toe on large arrays in high dimensions" because the answer is, almost certainly, nothing.
by rck on 5/18/2025, 1:11:40 PM
Just about everything that a non-specialist in combinatorics needs to know about counting can be found in Rota's twelvefold way, which lists the 12 counting problems that you can define for finite sets and shows how to solve them:
https://en.wikipedia.org/wiki/Twelvefold_way
This also takes care of most of discrete probability.
by qazxcvbnm on 5/18/2025, 4:07:40 PM
For those who are not aware, knowing how to count the number of structures is (nearly) the same as knowing how to encode said structure as an integer (space-optimally) (the naive general algorithm would not have good time complexity); to convert to integer, simply define some ordering on said structures, enumerate until you find your structure, the index of the structure is the integer encoding; conversely, to decode, simply list all structures and pick the structure with the index of the integer.
by getnormality on 5/18/2025, 3:30:00 PM
I think the best single thing for programmers to know about combinatorics is combinatorial data structures. If you have a collection of objects and you need to iterate over all possible combinations, subsets, or permutations of that collection, libraries like Python's itertools do this for you. The resulting code will be clearer, more concise, and more reliable than if you reinvent the wheel with some hand-coded rat's nest of loops.
If you need to know how long that's going to take, you'll need to know some enumerative combinatorics.
by jmount on 5/18/2025, 5:30:19 PM
As a fan of combinatorics, I love people looking into the topic. Though most of what a programmer would find useful are approximations or trends which are handled well by the Master theorem ( https://en.wikipedia.org/wiki/Master_theorem_(analysis_of_al... ). For those deeply interested in the deep math of combinatorics I recommend Flajolet, Sedgewick, *Analytic Combinatorics, Cambridge 2009.
by McUsr on 5/20/2025, 7:59:11 AM
I found the way of counting the number of permutations useful.
The Hockey stick identity was something long forgotten and fun re-discovering.
The way they are generated not so much.
So, Sedgewick has an algorithm for generating permutations that are highly efficient, and ijust as difficult to grasp. But there is a paper out there where he explains the algorithm graphically, which makes it understandable.
So I haven't worked through the way to get the composition that is the n'th permutation yet, but I guess I will suffer.
It is not well written, and for instance the wrong term for partition, versus composition is made in the explanatory graphic at the top of the article.
Still, I think it was worth reading, I have made several programs utilizing permutations, and I might improve one or two of them after having read this, with some new knowledge.
by johnisgood on 5/18/2025, 9:11:35 AM
What is the difference between integer compositions and integer partitions? It says a composition is just an ordered partition of an integer, but according to this article, number 4 can be partitioned into 5 parts, but apparently has 8 compositions. I find the 8 compositions much more accurate, but I do not get why it would not have 8 partitions.
by rendaw on 5/19/2025, 4:46:30 AM
I do think this is something that's relevant to most programmers unlike other commenters -- but the article goes from "counting database IDs" (a good practical use case!) to "integer partitions" and I was immediately lost. No explanation of how those relate to calculating the database ID space, how those fit into the bigger scheme, etc.
I think the article needs to demonstrate to the reader how every section is relevant to them - either by building off a relevant issue discussed in a previous section or tying it to some real world use case.
by barbazoo on 5/18/2025, 2:14:23 PM
I didn’t quite get from the write up what it is that every programmer should know about enumerative combinatorics or why it’s a relevant topic for programmers at all honestly.
by relaxing on 5/18/2025, 11:52:03 AM
Anyone else have the combinatorics song from Square One TV forever burned into their brain?
A Cyndi Lauper soundalike explains how many unique bands she can form by choosing from an expanding pool of musicians. Catchy!
by Etheryte on 5/18/2025, 9:26:25 AM
Don't the title illustration and the actual content of the article mix up which is which?
by tmoertel on 5/18/2025, 1:14:06 PM
What's the deal with this notice, presumably injected by GitHub into the hosted code samples in the article:
> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below.
by pestatije on 5/15/2025, 1:35:42 PM
why?
by louthy on 5/18/2025, 7:17:20 PM
“Why every programmer should ignore articles with ‘every’ in the title”
I find the presentation a bit confusing and I'm already very familiar with this material.
From a purely mathematical point of view, why this choice of topics? You correctly point out that counting partitions has no closed formula, but there are a lot of related problems (Sitrling numbers of the two kinds for example) which are of more practical utility (e.g. they are related to sums of powers formulas). If that's too advanced for your audience then why not present more standard tricks like combinations with replacement aka stars and bars?
From a programmer's point of view, you could have focused more on how to generate subsets, permutations, partitions etc. in a memory-efficient way, for example how the Python stdlib does it.
Also, the factorial number system and the binomial base of univariate polynomials are definitely not "alternatives to base 2 in computer architectures".
Don't take this the wrong way but I struggle to see who you are writing for.