# Calculate Probability that X amount of N die are equal to Y?

Update --- I think I see my problem... in the example at Stack Exchange Question it shows 5C3 5C4 and 5C5... if I have researched this out, this means 5 combinations choose X. If so, what is that calculation? (head is spinning right now... so break time) (that's the part I think I need to put in my code below)

I'm trying to write a function for my Computer Opponents in playing a dice game.

For all computer opponents:

-knows the value of its own dice (can have between 1 and 5 dice in it's hand)

-knows the total amount of die left in the game (between 2 and 4 players in the game, so 4 and 20 die total)

-knows the incoming bid (i.e. previous player bids there are six-4's, or four-2's, etc)

My decision tree for the computer to either raise or bid is based upon: -checking own dice for definite Raise or Call situation (i.e. incoming bid is three-2's, and computer has 4 2's in hand, for sure Computer will do a raise since computer has three-2's OR if incoming bid is six-4's, and total Die remaining is 8, and computer has 3 die in hand.. none of which are 6's, then Call)

-if neither definite Raise or Call, calculate chance that existing bid is valid, and then Random generate a number.. if the Random Number exceeds the chance that is calculated then Raise, else call.

In order to calculate the probability that the remaining die contain the rest of the bid dice, and in looking through samples here (I knew I should have paid more attention in my statistics class) I THINK what I need to do is add up the probabilities like so:

Examples: 10 die remaining, 5 in my (computer) hand. Current bid is four-3's. In my hand is two-3's, so need to calculate the probability that two of the remaining 5 dice are 3's.

or 20 die remaining, 5 in my (computer) hand. Current bid is six-4's. In my hand are two-4's, so need to calculate the probability that four of the remaining 15 dice are 4's.

In all cases.. that leaves me with adding up the probabilities such:

P(N dice (of the remaining dice) match the incoming value) (i.e. five-3's, or 15-4's) + P(N-1 dice match the incoming value) (i.e. four-3's or 14-4's).. and keep subtracting from N until I reach the value of the number of Dice I am trying to find (i.e. 5-3 because I need probability of two-4's, or 15-11 because I need probability of four-4's)

If that logic is correct (and makes sense) what do I need to keep track of each time through a loop?

Right now I set initial conditions (example):

TotalDiceLeftToLookThrough = 11 NumberOfDiceThatBidderNeeds = 3 CurrentDieToCalculateProbability = 11 PowerForNotAppearing = 1; TotalProbability = 0;

TotalProbability = (1/6)^CurrentDieToCalculateProbability ((1/6)^11)

CurrentDieToCalculateProbability -= 1 (now equals 10)

while(CurrentDieToCalculateProbability >= NumberOfDiceThatBidderNeeds)

TotalProbability += TotalDiceLeftToLookThrough * (5/6)^PowerForNotAppearing * (1/6)^CurrentDieToCalculateProbability

CurrentDieToCalculateProbability -= 1

PowerForNotAppearing += 1

Loop


But I think I am missing something in my loop... anyone able to explain what I need in my Loop would be greatly appreciated!

I am trying to follow along with the question here StackExchange Question but I do not come up with the answer 276/6^5, so not quite sure what I am missing in my understanding... (I get 276/6^5 = .03549, and if I run thru the problem with substitution (5∗(1/6)^3∗(5/6)^2)+(5∗(1/6)^4∗(5/6)^1)+(5∗(1/6)^5) I get .019933 and if I do this:((1/6)^3 * (5/6)^2) + ((1/6)^4 * (5/6)^1) + ((1/6)^5) I get .00398 )

Update - After pulling hair out.. the code works for dice up to three.. but then it breaks bad... So, I'm not there yet. looking for any general solution that would work for N dice such that Probability of X of N being the same die is calculated. (grrr, much prefer Vectors to this! :) )

-
I looked again at the calculation there. It is correct. – André Nicolas Aug 31 '13 at 6:47
Well, can you walk me through it then? I see this: favorite My approach is find P that exactly 3 dice are 4 + exactly 4 dice are 4 + exactly 5 dice are 4. (5C3∗(1/6)3∗(5/6)2)+(5C4∗(1/6)4∗(5/6)1)+(5C5∗(1/6)5) = 276/6^5 – user92447 Aug 31 '13 at 8:21
Well, can you walk me through it then? I see 276/6^5 = .03549. Yet if I follow EXACTLY as I see the sample I get .01999 (and If I leave off the multiply by 5Cx, I get .00398) So I don't know what is correct.... as I don't see any other examples where you multiply by 5 x (1/6)^5 (in that example, I do see where you multiply by 5 * (1/6)^4 * (5/6)^1) – user92447 Aug 31 '13 at 8:27
$\binom{5}{3}=10$, so first term is $\frac{250}{6^5}$. Second term is \frac{25}{6^5}$. Third is$\frac{1}{6^5}\$. That's on the linked problem. I have not read the current problem, avoid all problems that might involve debugging code, have had to do enough of that for real! – André Nicolas Aug 31 '13 at 14:38

My issue was not understanding the 5C3 , 5C4 notation, which in the nCx notation (combination of n items, choose x) which I found explanation on how to do that here: boxes and stacking them options

so now the loop is updated to handle the nCx portion and works as expected... (whew, I want a drink)

while(CurrentDieToCalculateProbability >= NumberOfDiceThatBidderNeeds)

TotalProbability += nCx(TotalDiceLeftToLookThrough, CurrentDieToCalculateProbability) * (5/6)^PowerForNotAppearing * (1/6)^CurrentDieToCalculateProbability

CurrentDieToCalculateProbability -= 1

PowerForNotAppearing += 1

Loop

-