Improve this recursive code please!

Steven Taschuk staschuk at telusplanet.net
Sun May 11 16:18:10 EDT 2003


Quoth I:
  [...]
> Not a mathematician, but the number of arrangements for m bricks
> and n bins is
>     m+n-1 choose m
> Proving this by induction is not difficult, though as usual for
> such proofs, neither is it particularly, er, insight-bringing.  I
> don't see a combinatoric proof at the moment, but no doubt there's
> a nice one.

Should have been obvious...

Arrange m Os and n-1 |s in a row.  The |s are bin boundaries; the
Os are bricks.  Example, with eight bricks in four bins:
    O O O | O | | O O O O
That's the arrangement (3, 1, 0, 4).

This is equivalent to replacing n-1 of m+n-1 Os with |s, so
there's m+n-1 choose n-1 ways to do it.  (Note that m+n-1 choose m
= m+n-1 choose n-1.)

-- 
Steven Taschuk                  staschuk at telusplanet.net
"Telekinesis would be worth patenting."  -- James Gleick





More information about the Python-list mailing list