Improve this recursive code please!

andrew cooke andrew at acooke.org
Sun May 11 16:22:40 EDT 2003


i think i was calling something (a test routine?) where no bricks == no
bins....

Steven Taschuk said:

> Quoth andrew cooke:
>   [...]
>> search for 1 1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490
>> at http://www.research.att.com/~njas/sequences/
>> (or sequence number A000041)
>>
>> it returns a single result - i can't work out how to link directly - and
>> there's no nice simple formula (which cheered me up because i spent a
>> while trying to figure one out, but couldn't).
>
> Ah, but that's the partition function p(n), the number of ways to
> store n bricks in any number of bins, where each bin is nonempty,
> and bins are not considered distinct.  For example,
>     4 = 3+1 = 2+2 = 2+1+1 = 1+1+1+1
> showing that p(4) = 5.  This is the answer to a different problem;
> in the OP's code, the bins are considered distinct, and there's a
> maximum number of bins.  That turns out to be more tractable; see
> my other post of a few minutes ago for a closed-ish form.
>
> (A direct link for the above sequence:
>     <http://www.research.att.com/cgi-bin/access.cgi/as/njas/sequences/eisA.cgi?Anum=A000041>
> .)
>
> --
> Steven Taschuk                               staschuk at telusplanet.net
> "What I find most baffling about that song is that it was not a hit."
>                                           -- Tony Dylan Davis (CKUA)
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
http://www.acooke.org/andrew





More information about the Python-list mailing list