Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Balls and Boxes Complicated Problem

  1. Aug 5, 2006 #1
    Consider a set box boxes. Say we have 30 boxes.

    And then we have x number of black balls and y number of white balls

    And these balls are stacked in the boxes. The total nuber of ways of stacking them is easy to find, but a much harder problem is to find the probability that for any one of the 30 boxes the ratio of black balls to white balls exceeds a certain value donoted as say 'p' where the number of black balls must exceed another variable denoted 'q' for this ratio to be valid.

    For example if you have 10 black balls 5 white balls and 30 boxes find the probability that in any one of those boxes there will be twice as many black balls than white balls assuming that there must be greater than 2 blacks balls in tat particular box. The balls are randomly placed in the boxes and the placement of one ball has no affect on the placement of another.
  2. jcsd
  3. Aug 5, 2006 #2


    User Avatar
    Science Advisor

    Order of stacking within the boxes does not matter. You know that for a given number of white balls and black balls in a given box (say 4 and 2), the number of ways that you could have those appear in that box is the same as the number of ways that you could arrange 6 black balls and 3 white balls in the remaining boxes. Add up the total ways for each number of white or black balls that satisfies the ratio and the minimum number of black balls, and divide by the total number of ways. I couldn't tell you if this is the quickest way to approach the problem, but it should work eventually.

    Edit: Since I'm learning Haskell, I tried this as an exercise
    Code (Text):

    prob w b s min r = satisfy w b s min r / total w b s min

    satisfy w b s min r = sum [countall (w - y) (b - x) (s - 1) | x <- [min..b], y <- [0..w], (y == 0 && x > 0) || x / y > r]

    total w b s min = countall w (b - min) s

    fac 0 = 1
    fac n = n * fac (n - 1)

    a `choose` b = fac a / (fac (a - b) * fac b)

    countall w b s = ((w + s - 1) `choose` w) * ((b + s - 1) `choose` b)
    This seems to work, but I haven't tested it much. For your example, r = 2, min = 3 (i.e. greater than 2), s = 30, w = 5, b = 10, prob gives a probability of about 0.98, which sounds about right.
    Last edited: Aug 6, 2006
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook