import random import numpy as np import matplotlib.pyplot as plt def descartes(ax, ran_x, ran_y, ax_title,x_label = "x", y_label = "y"): ax.set_xlabel(x_label, fontsize = 12) ax.set_ylabel(y_label, fontsize = 12) ax.set_xlim(ran_x[0], ran_x[1]) ax.set_ylim(ran_y[0], ran_y[1]) ax.set_title(ax_title, fontsize = 14) ax.grid() ax.axhline(0, color = "black") ax.axvline(0, color = "black") def check_face(h_face): flag1=True for i in [0,5]: for j in [1,2],[2,3],[1,3]: if h_face[i]==h_face[j[0]]: flag1=False break if h_face[i]==h_face[j[1]]: flag1=False break if h_face[j[0]]==h_face[j[1]]: flag1=False break return(flag1) fig = plt.figure(figsize = (5, 5)) ax = fig.add_subplot(111) title1 = "Kyoto University 2024 Math qu.1 NO1" random.seed(24) tdice=1000000 color_n=4 hexa_face=[1,2,3,4,5,6] ok_i=0 probability=[] descartes(ax, [0, tdice/10000], [0, 0.04],title1) for i in range(1,tdice): for j in range(6): hexa_face[j]=random.randint(1,color_n) if check_face(hexa_face) == True: ok_i+=1 if i%100 == 0: probability.append(ok_i/i) yy=probability xx = np.arange(len(yy)) ax.plot(xx ,yy , color = "blue") y1=[3/128]*len(xx) ax.plot(xx ,y1 , color = "red") plt.show()