質問のサイコロの確率の問題をPythonで解いてみました。(^_^;
5つのサイコロを同時にふるとき、出る目の組が(a,a,a,b,c)のように出る確率を求めよ。
まぁ、解釈によって別解もいろいろありそうですが、数学的には、{(5C3)*6}*(5P2)/6^5でいけそうですね。(^_^;
やっぱり、確率の問題は検算が難しいため、答えに確信が持てないことが多いですね。(^_^;
● ProbOfDice3.py
# coding: UTF-8 # ProbOfDice3.py from fractions import Fraction import itertools def toStr(li): return ''.join(li) N = '123456' total = cnt = 0 for p in itertools.product(N,repeat=5): total+=1 if not len(set(p))==3: continue a,b,c = list(set(p)) if not p.count(a)*p.count(b)*p.count(c)==3: continue pass # チェックを潜り抜けたものをカウント cnt+=1 ## print(toStr(p)) print("%d/%d = %s"%(cnt,total,Fraction(cnt,total)))
●実行結果
1200/7776 = 25/162
ちなみに、6つのサイコロの問題もやってみました。(^_^;
6つのサイコロを同時にふるとき、出る目の組が(a,a,a,b,b,c)のように出る確率を求めよ。
● ProbOfDice3a.py
# coding: UTF-8 # ProbOfDice3a.py from fractions import Fraction import itertools def toStr(li): return ''.join(li) N = '123456' total = cnt = 0 for p in itertools.product(N,repeat=6): total+=1 if not len(set(p))==3: continue a,b,c = list(set(p)) if not p.count(a)*p.count(b)*p.count(c)==6: continue pass # チェックを潜り抜けたものをカウント cnt+=1 ## print(toStr(p)) print("%d/%d = %s"%(cnt,total,Fraction(cnt,total)))
●実行結果
7200/46656 = 25/162
※参考URL
●質問のサイコロの確率の問題をPythonで解いてみた。 - rscのブログ
●知恵袋で見つけたサイコロの確率の問題をPythonで解いてみた。 - rscのブログ