In [1]:
import numpy as np, pandas as pd
In [2]:
from IPython.display import Image
Image(filename="C:\\Users\\Admin\\Desktop\\quiz.jpg") 
Out[2]:

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.

In [45]:
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
In [46]:
df
Out[46]:
0 1 2 3 4 5
1 1.0 NaN NaN NaN NaN NaN
2 2.0 3.0 NaN NaN NaN NaN
3 4.0 5.0 6.0 NaN NaN NaN
4 7.0 8.0 9.0 10.0 NaN NaN
5 11.0 12.0 13.0 14.0 15.0 NaN
6 16.0 17.0 18.0 19.0 20.0 21.0
In [47]:
dot_choiced = np.random.choice(np.arange(1,22,1))
dot_choiced
Out[47]:
12

Below the dataframe after the elimination of the dot number 12

In [48]:
new = pd.DataFrame(np.where(df.iloc[:,:] == dot_choiced, np.nan, df), index= range(1,7,1))
new
Out[48]:
0 1 2 3 4 5
1 1.0 NaN NaN NaN NaN NaN
2 2.0 3.0 NaN NaN NaN NaN
3 4.0 5.0 6.0 NaN NaN NaN
4 7.0 8.0 9.0 10.0 NaN NaN
5 11.0 NaN 13.0 14.0 15.0 NaN
6 16.0 17.0 18.0 19.0 20.0 21.0

We toss the die and see the top face

In [50]:
top_face = np.random.choice(np.arange(1,7,1))
top_face 
Out[50]:
4

We count how many 'integer' dots are present on that face

In [52]:
new.loc[top_face].count()
Out[52]:
4

Now we run the MC simulation with the same algorithm to find the answer of the problem

In [53]:
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
In [54]:
print('Probability is: {}'.format(counter / N))
Probability is: 0.52294