Skip to content

Instantly share code, notes, and snippets.

@andreabazerla
Last active April 2, 2024 19:04
Show Gist options
  • Save andreabazerla/0ab21e80798669a296f7398b64df596b to your computer and use it in GitHub Desktop.
Save andreabazerla/0ab21e80798669a296f7398b64df596b to your computer and use it in GitHub Desktop.
Mr. Brownie
import matplotlib.pyplot as plt
from decimal import Decimal, getcontext
smarties = 5
colors = 5
start_index = 2
end_index = 10
#Fixed numbr of smarties, variable number of colors
colors_probability_list = []
for i in range(start_index, end_index+1):
colors_probability_list.append(Decimal(i/(i**smarties))*100)
#Fixed number of colors, variable number of smarties
smarties_probability_list = []
for i in range(start_index, end_index+1):
smarties_probability_list.append(Decimal(5/(colors**i))*100)
x = range(start_index, end_index+1)
plt.figure(figsize=(8, 5))
plt.plot(x, smarties_probability_list, color='#6e00ff', linewidth=5, label='Quantità degli smarties')
plt.plot(x, colors_probability_list, color='#ff4500', linewidth=5, label='Numero dei colori')
plt.axvline(x=5, color='black', linestyle='--')
plt.xticks(x, [int(xi) for xi in x])
plt.legend()
plt.xlabel('Quantità degli smarties/Colori degli smarties')
plt.ylabel('Probabilità in %')
plt.title('Mr. Brownie')
plt.ylim(-0.01, 0.02)
plt.xlim(9, end_index)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment