Imagine a game similar to yahtzee, where the goal is to get roll 5 times the same number with 5 dice. Which number it is, doesn't matter, however the rules are a little different:
- You get a maximum of 5 tries.
- After each try, you must remove the dice which show the number occurring the most. (e.g. if you throw 1,1,2,4,5, you remove both 1's and continue with 3 dice; if you throw 1,1,2,2,5 the rule is to pick the highest number of the most occurring so keep 2,2 and throw 3 in the next turn).
This seems pretty straightforward but imagine the following situation:
- Throw 1,2,4,5,6: keep 6 and continue with 4 dice
- Throw 2,2,3,5 + 6(kept): keep 2,2 (as it occurs more than 6) and continue with 3 dice
- Keep throwing until you've reached either 5 of the same number or you run of of tries
So the value of the dice you're currently keeping out of the game can shift according to your throw. The question is: what is the probability of succeeding in such a game in a maximum of 5 tries
I've written a small script in Python with simulates the game but I can't figure out how to calculate it using exact probabilities. A run of my script with 1 million samples yields a probability of approximately 17%
EDIT: Thanks for all the insight guys. I eventually went for a Markov-Chain solution which takes into account the probabilities of shifting states:
import math as m
def binomial(n,k,p):
if n>=k:
n_k = m.factorial(n)/(m.factorial(k)*m.factorial(n-k))
p_k = p**k
binom = n_k*p_k*(1-p)**(n-k)
else:
binom = 0
return binom
def initialState():
state_1 = 5*4*3*2/(6**4) #independent of first throw make a different roll each time
state_3 = 6*binomial(5,3,1/6) #exactly 3 successes in 5
state_4 = 6*binomial(5,4,1/6) #exactly 4 successes in 5
state_5 = 6*binomial(5,5,1/6) #exactly 5 successes in 5
state_2 = 1-state_1-state_3-state_4-state_5
return [state_1,state_2,state_3,state_4,state_5]
def stateShiftProbability():
shift = [[0]*5 for _ in range(5)]
#chance of state 1 staying 1 = none of the 4 thrown dice match the original
# and we throw no new pairs or more
shift[0][0] = 5*4*3*2/(6**4)
#chance of state 1 to state 3 = chance to throw 2 more of the same value or
# 3 of a new value
shift[0][2] = binomial(4,2,1/6)+5*binomial(4,3,1/6)
shift[0][3] = binomial(4,3,1/6)+5*binomial(4,4,1/6)
shift[0][4] = binomial(4,4,1/6)
#chance of state 1 to state 2 = 1 of the 4 thrown dice match the original
# + the chance that we throw a new pair (given that the other 2 dice aren't
# equal to the orignal dice). Quite complex, so we just take the remaining
# value
shift[0][1] = 1-sum(shift[0])
#from state 2 we follow a similar logic
shift[1][2] = binomial(3,1,1/6)+5*binomial(3,3,1/6)
shift[1][3] = binomial(3,2,1/6)
shift[1][4] = binomial(3,3,1/6)
shift[1][1] = 1-sum(shift[1])
shift[2][2] = binomial(2,0,1/6)
shift[2][3] = binomial(2,1,1/6)
shift[2][4] = binomial(2,2,1/6)
shift[3][3] = 5/6
shift[3][4] = 1/6
shift[4][4] = 1
print(shift)
return shift
def getProbabilities(tries):
initial_state = initialState()
state_shift = stateShiftProbability()
current_state = initial_state[:]
print("After",1,"throw, we are successful", current_state[4]*100,"% of the time")
for i in range(tries-1):
new_state = [0]*5
for j in range(5): #every state j
# a new state is formed by the probability of a state remaining
# unchanged + new population shifting towards this state
for k in range(5):
new_state[j] += state_shift[k][j]*current_state[k]
current_state = new_state[:]
print("After",i+2,"throws, we are successful", current_state[4]*100,"% of the time")
max_number_of_attempts = 5
getProbabilities(max_number_of_attempts)
This results in the exact probabilities I wanted:
After 1 throw, we are successful 0.07716049382716046 % of the time
After 2 throws, we are successful 1.2631458619112939 % of the time
After 3 throws, we are successful 4.6028642525699 % of the time
After 4 throws, we are successful 10.057536103294314 % of the time
After 5 throws, we are successful 17.05067236780467 % of the time
The odds are approximately 17.05067...% so your simulation is pretty accurate. Here are exact odds for the 6 winning rolls:
((1, 1, 1, 1, 1), Fraction(451727069, 19591041024)) ((2, 2, 2, 2, 2), Fraction(1208621087, 58773123072)) ((3, 3, 3, 3, 3), Fraction(1516264807, 58773123072)) ((4, 4, 4, 4, 4), Fraction(1693008047, 58773123072)) ((5, 5, 5, 5, 5), Fraction(17336750593, 528958107648)) ((6, 6, 6, 6, 6), Fraction(20896486973, 528958107648))And here is the program that I used to calculate it: