Place n indistinguishable items into k distinguishable boxes
castironpi at gmail.com
castironpi at gmail.com
Thu Feb 28 14:54:20 EST 2008
On Feb 28, 10:07 am, Mark Dickinson <dicki... at gmail.com> wrote:
> On Feb 28, 5:02 am, Michael Robertson <mcrobert... at hotmail.com> wrote:
>
> > Thanks again for your efforts here. This particular problem didn't
> > appear in any course I took...certainly similar problems did.
>
> And here's the obligatory not-very-obfuscated one-liner:
>
> from itertools import combinations as c; boxings=lambda n,k:([s[i
> +1]+~s[i] for i in range(k)] for s in [[-1]+list(t)+[n-~k] for t in
> c(range(n-~k),k-1)])
This calls for an obfuscation metric, several books, and two personal
references. What is ~k doing in there twice?
(Aside: throw in an obligatority one too. Sigh.)
More information about the Python-list
mailing list