I don't know how many times I stared at that code without seeing the error.<br><br>Thanks so much!<br><br>Phillip<br><br><div class="gmail_quote">On Fri, Sep 23, 2011 at 1:26 PM, Arnaud Delobelle <span dir="ltr"><<a href="mailto:arnodel@gmail.com">arnodel@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">On 23 September 2011 21:09, Dr. Phillip M. Feldman<br>
<<a href="mailto:Phillip.M.Feldman@gmail.com">Phillip.M.Feldman@gmail.com</a>> wrote:<br>
><br>
> A few weeks ago, I wrote a class that creates an iterator for solving the<br>
> general unlabeled-balls-in-labeled boxes occupancy problem. Chris Rebert<br>
> converted my code to a generator, which made the code cleaner, and I<br>
> subsequently simplified it somewhat further.<br>
><br>
> My problem is the following: All of these versions of the code work fine for<br>
> very small problems, but do not produce the full set of occupancy<br>
> distributions for larger problems. The following sample input and output<br>
> show what happens with two balls and two boxes (to keep things simple, I've<br>
> made the boxes large enough so that each box can hold both balls).<br>
><br>
> In [6]: x= balls_in_labeled_boxes(2,[2,2])<br>
><br>
> In [7]: list(x)<br>
> balls=2, box_sizes=[2, 2]<br>
> About to make recursive call. balls_in_other_boxes=0, box_sizes=[2]<br>
> i=0, distribution_other=(0,)<br>
> About to make recursive call. balls_in_other_boxes=1, box_sizes=[2]<br>
> i=0, distribution_other=(1,)<br>
> About to make recursive call. balls_in_other_boxes=2, box_sizes=[2]<br>
> i=0, distribution_other=(2,)<br>
> Out[7]: [(2, 0), (1, 1), (0, 2)]<br>
><br>
> Note that Out[7] above gives the correct result, showing all three possible<br>
> distributions. Now lets try the same thing with three boxes.<br>
><br>
> In [8]: x= balls_in_labeled_boxes(2,[2,2,2])<br>
><br>
> In [9]: list(x)<br>
> balls=2, box_sizes=[2, 2, 2]<br>
> About to make recursive call. balls_in_other_boxes=0, box_sizes=[2, 2]<br>
> i=0, distribution_other=(0, 0)<br>
> About to make recursive call. balls_in_other_boxes=1, box_sizes=[2, 2]<br>
> i=0, distribution_other=(1, 0)<br>
> About to make recursive call. balls_in_other_boxes=2, box_sizes=[2, 2]<br>
> i=0, distribution_other=(2, 0)<br>
> i=1, distribution_other=(1, 1)<br>
> Out[9]: [(2, 0, 0), (1, 1, 0), (0, 2, 0), (0, 1, 1)]<br>
><br>
> When there are no balls in the initial box, the recursive call should<br>
> produce the same three occupancy distributions that we saw above, but one of<br>
> them is now missing. If someone can shed light on why this is happening, I'd<br>
> be grateful.<br>
<br>
Line 46:<br>
<br>
for distribution_other in _balls_in_unlabeled_boxes(<br>
<br>
Should be:<br>
<br>
<br>
for distribution_other in _balls_in_labeled_boxes(<br>
<br>
HTH<br>
<font color="#888888"><br>
--<br>
Arnaud<br>
</font></blockquote></div><br>