Generating all combinations

S

Steven D'Aprano

After all, everybody knows that for m items taken n at a time, the
counts are

perm w/repl = m**n
comb w/repl = (m+n-1)!/(n!(m-1)!)
perm wo/repl = m!/(m-n)!
comb wo/repl = m!/(n!(m-n)!)


"Everybody" knows? Be careful with those sweeping generalizations.
Combinatorics is a fairly specialized area not just of programming but
mathematics as well.

I've done a spot poll of four developers here (two juniors and two
seniors) and *not one* could give all four formulae correctly first go.
One guy didn't recognize the terms (although on being reminded, he got
two of the four formula). Another one, a self-professed maths-geek,
worked them out from first principles.
 
M

Mensanator

"Everybody" knows? Be careful with those sweeping generalizations.
Combinatorics is a fairly specialized area not just of programming but
mathematics as well.

I would expect that. That was supposed to be funny. :)
I've done a spot poll of four developers here (two juniors and two
seniors) and *not one* could give all four formulae correctly first go.
One guy didn't recognize the terms (although on being reminded, he got
two of the four formula). Another one, a self-professed maths-geek,
worked them out from first principles.

I didn't know all of them either. I had to look
them up in the source code of the combinatorics
library I wrote for myself (I use that stuff a
lot in my research). BTW, I really appreciate the
links posted a while ago on how to search for text
in .py files on Windows. Could not have found them
otherwise. I must have a dozen copies of the module
on each of 4 disks (two hard & 2 flash) but the
comments containing those formulae was only in a
single place.

There was a subtle point. A function that would
return such counts is fine - provided you don't
have to actually count them! I'm sure Mr. Hettinger
knows that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,786
Messages
2,569,626
Members
45,328
Latest member
66Teonna9

Latest Threads

Top