Expected number of trials

91 Views Asked by At

In a box there are 4 balls. Red, Yellow, Blue and Green. We draw a ball from the box. If the ball is red then we replace it by a yellow ball, if the ball is yellow then we replace it by a blue ball, if the ball is blue then we replace it by a green ball, if the ball is green then we replace it by a red ball. Find the expected no of drawings such that all balls will be of same colour.

1

There are 1 best solutions below

0
On

This is an absorbing Markov chain with $35$ states, as indicated by lulu in his hint. The four "monochromatic" states are absorbing. The procedure for solving this problem is given in the Wikipedia article cited in my hint.

I wrote the following python script to solve the problem:

from collections import namedtuple
from itertools import product
import numpy as np

Box = namedtuple("Box", 'r y b g'.split())

def children(box):
    if max(box) ==4:
        return 4*[box]
    answer = []
    r,y,b,g=box
    for _ in range(r):
        answer.append(Box(r-1, y+1, b, g))
    for _ in range(y):
        answer.append(Box(r, y-1, b+1, g))  
    for _ in range(b):
        answer.append(Box(r, y, b-1, g+1))  
    for _ in range(g):
        answer.append(Box(r+1, y, b, g-1))
    return answer

boxes = [Box(r,y,b,g) for r,y,b,g in product(range(5), repeat=4) if r+y+b+g==4]
boxes.sort(key=lambda x:max(x))
boxes = {b:i for i,b in enumerate(boxes)}
P=np.zeros((35,35), dtype = float)
for b in boxes:
    i = boxes[b]
    for c in children(b):
        j = boxes[c]
        P[i,j] += 1
P /= 4
Q= P[:31, :31]
I = np.eye(31)
N=np.linalg.inv(I-Q)
one = np.ones(31)
start = boxes[(1,1,1,1)]
wait=sum(N.transpose())[start]
print('Expected waiting time:', wait) 

It printed

Expected waiting time: 69.4666666667