techmologist
- 305
- 12
CRGreathouse said:You're right, that problem is hard. (I didn't think so at first glance.) Here's Mathematica code that solves the problem, if I haven't made any mistakes:
Code:P[r_,0,s_] := 0 /; s < 3 P[0,b_,s_] := 0 /; s < 3 P[r_,b_,s_] := 1 /; s >= 3 P[r_,b_,0] := ( P[r-1,b,1]*r + P[r,b-1,0]*b + ( P[r-1,b,2]*r/(R+B) + P[r,b-1,0]*b/(R+B) + ( R/(R+B) + P[r,b-1,0]*b/(R+B) )*(R-r)/(R+B) )*(R-r) ) * (b B^2-b B r+3 b B R+b r^2-3 b r R+3 b R^2+B^2 r-B r^2+3 B r R+R^3)/(b B-b r+2 b R+B r+R^2)^2 P[r_,b_,1] := P[r-1,b,2]*r/(R+B) + P[r,b,2]*(R-r)/(R+B) + P[r,b-1,0]*b/(R+B) + P[r,b,0]*(B-b)/(R+B) P[r_,b_,2] := R/(R+B) + P[r,b-1,0]*b/(R+B) + P[r,b,0]*(B-b)/(R+B) R = 5; B = 8; P[5, 8, 0]
Unfortunately Mathematica doesn't seem to use memoization here, since it hasn't found the answer yet (though it can handle small instances). There are only 3(5 + 1)(8 + 1) = 162 different function calls in this case, so if it was memoizing it would be pretty quick.
Code overview: R is the number of red balls, B is the number of nonred, r is the number of unpicked red, b is the number of unpicked nonred, and s is the number of consecutive red balls that have been previously pulled.
Edit: the code doesn't work properly because it doesn't handle the cases r = 0, b > 0 or r > 0, b = 0 properly. Maybe I'll work on this later.
Cool. Thanks for taking a look at it, CRGreathouse. I haven't even attempted the problem with replacement. It looks like a doozy.
I'm going to go ahead and post my solution to the easier problem, which I feel sure is what the OP was asking. I was going to give him a chance to ask questions first, but it's been over 24 hrs, so I'll just put a spoiler warning on it.