Cat and mouse maze – How long does the mouse survive

probabilityrandom walk

The diagram below shows the floor plan of a house with six rooms: in room 1 is a mouse which will change rooms every minute, first moving at t = 1 and choosing a door to an adjoining room at random. In room 6 is a sleeping but hungry cat which will instantly wake if the mouse should enter. How long on average can we expect the mouse to survive?

Maze

I attempted this problem by setting up and solving simultaneous equations in terms of 5 $e_i$'s, the average survival time from room $i$. However, when I simulated this in Sage, I got a different answer.

Is the method below correct?

$$e_1=(e_4+1)/2+(e_2+1)/2$$$$e_3=e_2+1$$$$e_4=e_1+1$$$$e_2=(e_3+1)/3+(e_5+1)/3+(e_1+1)/3$$$$e_5=1/2+1/2(e_2+1)$$

Solving, $e_1=19$. Therefore the mouse survives 19 minutes on average.

In simulation, I got around 16 minutes average survival time.

def Mouse(): 
    counter=0
    room=1
    while room<6:
        if room==1:
            if randint(0,1)==0:
                room=4
            else:
                room=2
            counter=counter+1
        elif room==2:
            x=randint(0,2)
            if x==0:
                room=1
            if x==1:
                room=5
            if x==2:
                room=3
            counter=counter+1
        elif room==3:
            room=2
            counter=counter+1
        elif room==4:
            room=1
            counter+counter+1
        elif room==5:
            counter=counter+1
            if randint(0,1)==0:
                room=2
            else:
                room=6
    return(counter)
def MouseSim():
    total=0
    for i in range(10000):
        x=Mouse()
        total=total+x
    return N(total/10000)
MouseSim()
Out[19]:
15.9815000000000

Best Answer

Your calculations are correct, and the answer is $19$. In your "room=4" case, you have a line counter+counter+1 while it should say counter=counter+1 instead. If you change this, the code returns an answer around $19$, like it should.

You can be less likely to make these sorts of issues if your line incrementing the counter is placed outside all of the if statements, since you increment the counter regardless of the value of room.

Related Question