import numpy as np, pandas as pd
from IPython.display import Image
Image(filename="C:\\Users\\Admin\\Desktop\\quiz.jpg")
We create a dataframe where each row is a face of the die, and each dot in every row is labeled with a positive integer if present on that face, else with the label 'not a number'.
In this way we respect the dots-uniformity distribution condition of the riddle.
Let's see an example of how the algo works for 1 trial.
diz = {1:[1],
2:[2,3],
3:[4,5,6],
4:[7,8,9,10],
5:[11,12,13,14,15],
6:[16,17,18,19,20,21]}
df = pd.DataFrame(dict([ (k,pd.Series(v)) for k,v in diz.items() ])).T
df
dot_choiced = np.random.choice(np.arange(1,22,1))
dot_choiced
Below the dataframe after the elimination of the dot number 12
new = pd.DataFrame(np.where(df.iloc[:,:] == dot_choiced, np.nan, df), index= range(1,7,1))
new
We toss the die and see the top face
top_face = np.random.choice(np.arange(1,7,1))
top_face
We count how many 'integer' dots are present on that face
new.loc[top_face].count()
Now we run the MC simulation with the same algorithm to find the answer of the problem
N = 100000
counter = 0
for i in range(N):
dot_choiced = np.random.choice(np.arange(1,22,1))
new = pd.DataFrame(np.where(df.iloc[:,:] == dot_choiced, np.nan, df), index= range(1,7,1))
top_face = np.random.choice(np.arange(1,7,1))
if new.loc[top_face].count() % 2 != 0:
counter += 1
print('Probability is: {}'.format(counter / N))