# Get Out Of Jail

Python Puzzles

Back to the Python! homepage

You are locked in a jail cell and demand to be released because you are innocent. The warden tells you he will release you if you can win 2 straight games of checkers. But you must play at least one game against the warden and one game against the sheriff. You know the sheriff plays a better game of checkers then the warden.

Do you have a better probability of winning if you play [Warden -> Sheriff -> Warden] or [Sheriff -> Warden -> Sheriff]? Remember, the sheriff is a better checkers player then the warden, and you must win 2 straight games.

You have a higher probability of winning 2 straight games playing [Sheriff -> Warden -> Sheriff].

The probability changes depends on the probability variables you set for the warden and the sheriff. But given you must win the second game in order to get out of jail, it is best to play the weaker opponent second and hope you can win 1 of 2 from the tougher opponent.

```# -*- coding: utf-8 -*-
"""
Created on Mon Jan 25 18:28:14 2021

@author: smpet
"""

import numpy as np

sheriff = .75
warden = .5
scenario1 = []
scenario2 = []

for _ in range(1_000_000):

##########################################################################
##########################################################################
#sheriff -> warden -> sheriff
winning_count = 0

#play 1
sheriff_play1 = np.random.binomial(1,sheriff,1).item()
winning_count += 1 if sheriff_play1 == 0 else winning_count

#play 2
warden_play1 = np.random.binomial(1,warden,1).item()
winning_count = winning_count + 1 if warden_play1 == 0 else 0

if winning_count == 2: scenario1.append(1)

#play 3
sheriff_play2 = np.random.binomial(1,sheriff,1).item()
winning_count = winning_count + 1 if sheriff_play2 == 0 else 0

if winning_count >= 2: scenario1.append(1)

##########################################################################
##########################################################################
#sheriff -> warden -> sheriff

winning_count = 0

#play 1
warden_play1 = np.random.binomial(1,warden,1).item()
winning_count += 1 if warden_play1 == 0 else winning_count

#play 2
sheriff_play1 = np.random.binomial(1,sheriff,1).item()
winning_count = winning_count + 1 if sheriff_play1 == 0 else 0

if winning_count == 2:
scenario2.append(1)
winning_count = 0

#play 3
warden_play2 = np.random.binomial(1,warden,1).item()
winning_count = winning_count + 1 if warden_play2 == 0 else 0

if winning_count >= 2: scenario2.append(1)

print(len(scenario1))
print(len(scenario2))
```