fork download
  1. #!/usr/bin/env python3
  2.  
  3. from itertools import product
  4. from functools import reduce
  5. from fractions import Fraction
  6. from operator import mul
  7.  
  8. if __name__ == '__main__':
  9. # 3個のサイコロを同時に振るとき、出る目のエビデンス
  10. q = lambda : product(range(1, 7), repeat = 3)
  11. # 出た目の積が12以下になる確率
  12. print(Fraction(len([i for i in q() if reduce(mul, i) <= 12]), len(list(q()))))
  13. # 出た目の積が12以下になる候補
  14. print([i for i in q() if reduce(mul, i) <= 12]) # 結果には (2, 3, 3) に類する組は含まれない
  15.  
Success #stdin #stdout 0.03s 10312KB
stdin
Standard input is empty
stdout
7/27
[(1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 1, 4), (1, 1, 5), (1, 1, 6), (1, 2, 1), (1, 2, 2), (1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 2, 6), (1, 3, 1), (1, 3, 2), (1, 3, 3), (1, 3, 4), (1, 4, 1), (1, 4, 2), (1, 4, 3), (1, 5, 1), (1, 5, 2), (1, 6, 1), (1, 6, 2), (2, 1, 1), (2, 1, 2), (2, 1, 3), (2, 1, 4), (2, 1, 5), (2, 1, 6), (2, 2, 1), (2, 2, 2), (2, 2, 3), (2, 3, 1), (2, 3, 2), (2, 4, 1), (2, 5, 1), (2, 6, 1), (3, 1, 1), (3, 1, 2), (3, 1, 3), (3, 1, 4), (3, 2, 1), (3, 2, 2), (3, 3, 1), (3, 4, 1), (4, 1, 1), (4, 1, 2), (4, 1, 3), (4, 2, 1), (4, 3, 1), (5, 1, 1), (5, 1, 2), (5, 2, 1), (6, 1, 1), (6, 1, 2), (6, 2, 1)]