人が23人いるとき約50%の確率で誕生日が重なる
目的
人が23人集まれば、そのうちの一人の誕生日が約50パーセントの確率で他の人の誕生日と重複するという話を聞いたので、本当かどうか検証してみることにしました。
方法
実験にはPython3とMatplotlibを使います。今回の実験では1人から50人までを順次計算しました。
計算手順
計算式はいたってシンプルで、1-(ある一人の誕生日に対し他の人の誕生日が重ならない確率)をするだけです。
from pylab import *import matplotlib.pyplot as pltx = []y = []people = 50#人数を指定for i in range(people):x.append(i+1)probability = 1for j in range(i+1):probability *= (365-j)/365.0 #ある一人の誕生日が他の人の誕生日と重複しない確率print(str(i+1)+'人:',(1-probability)*100)y.append((1-probability)*100) #ある一人の誕生日が他の人と重複する確率xlabel('pepole')ylabel('percent')title('')plt.plot(x, y, 'o')plt.show()
結果
プログラムを実行すると、 1人: 0.0 2人: 0.27397260274 3人: 0.820416588478 4人: 1.63559124666 5人: 2.71355736998 6人: 4.04624836491 7人: 5.6235703096 8人: 7.43352923517 9人: 9.46238338892 10人: 11.6948177711 11人: 14.1141378322 12人: 16.7024788838 13人: 19.4410275232 14人: 22.3102512005 15人: 25.2901319764 16人: 28.3604005253 17人: 31.5007665297 18人: 34.6911417872 19人: 37.9118526032 20人: 41.1438383581 21人: 44.3688335165 22人: 47.5695307663 23人: 50.7297234324と 24人: 53.8344257915 25人: 56.8699703969 26人: 59.8240820136 27人: 62.6859282263 28人: 65.4461472342 29人: 68.0968537478 30人: 70.6316242719 31人: 73.0454633729 32人: 75.334752785 33人: 77.4971854176 34人: 79.531686462 35人: 81.4383238875 36人: 83.218210638 37人: 84.8734008216 38人: 86.4067821082 39人: 87.8219664367 40人: 89.1231809818 41人: 90.3151611482 42人: 91.4030471562 43人: 92.3922855656 44人: 93.2885368551 45人: 94.0975899466 46人: 94.8252843367 47人: 95.4774402833 48人: 96.0597972879 49人: 96.5779609323 50人: 97.0373579578 となり、23人目のところで50.7297234324という値が出ました。これで実験成功です。
作成した以下のグラフは、横軸が人数、縦軸がある一人の誕生日が他の人と重複する確率です。面白い形をしています。