Python Puzzles
You are conducting a controlled experiment where you have a single cell. After a certain and reoccurring amount of time, the cell has a 2/5 chance of dying, 2/5 chance of being idle, and a 1/5 chance of replicating. After a replication, each cell has the same amount of probability.
Given 1 million trials, what is the maximum number of cells produced?
I routinely get around 75 cells produced, given 1 million trials.
The probability of a trial creating 10 or more cells is only 2%. Given the chart below, you can see how the probability dramatically decreases once the trial begins.
import random
import matplotlib.pyplot as plt
import pandas as pd
result = []
for _ in range(1_000_000):
cell = []
cell.append(True)
while True in cell:
for x in range(len(cell)):
random_num = random.randint(1,5)
if cell[x] == True and random_num in (4,5):
cell[x] = False
elif cell[x] == True and random_num == 3:
cell.append(True)
result.append(len(cell))
print(max(result))
df = pd.Series(result)
df = df.value_counts()
plt.plot(df.index, df.values)
plt.title('Distribution of Cell Count')
plt.xlabel('Cell Count')
plt.ylabel('Frequency')
plt.show()