# -*- coding: utf-8 -*- """ 使用済みの手札や、自分が持っているので 他が出さないことがわかっている札の情報を無視した計算 (相手の出す札の分布が自分の出す札以外の均一な分布と仮定する) 確率論的に導出したのを全探索で一応確認する """ TEST = [] def prob_win(my, N=52): """ 全N枚中、下からmy番目(0-origin)のカードを出した際の 自分が中央値になる確率 """ c = my * (N - my - 1) * 2 p = float(c) / (N - 1) / (N - 2) return p def prob_gt(my, other, N=52): """ 自分以外の特定の1人がotherより大きな点で勝つ確率 """ if my < other: c = (N - other - 1) * (N - other - 2) / 2 elif my > other: c = (N - my - 1) * (N - my - 2) / 2 d = (my - other - 1) c += ((my - 1) * 2 - (d - 1)) * d / 2 else: c = (N - my - 1) * (N - my - 2) / 2 if TEST: return c, (N - 1) * (N - 2) return float(c) / (N - 1) / (N - 2) def _prob_gt(my, other, N=52): c0 = c = 0 for i in range(N): if i == my: continue for j in range(N): if i == j: continue if j == my: continue c0 += 1 if my < i < j and other < i: c += 1 if j < i < my and other < i: c += 1 return c, c0 def _prob_lt(my, other, N=52): c0 = c = 0 for i in range(N): if i == my: continue for j in range(N): if i == j: continue if j == my: continue c0 += 1 if my < i < j and other > i: c += 1 if j < i < my and other > i: c += 1 return c, c0 def prob_lt(my, other, N=52): """ 自分以外の特定の1人がotherより小さな点で勝つ確率 """ if my > other: c = other * (other - 1) / 2 elif my < other: c = my * (my - 1) / 2 d = (other - my - 1) c += ((N - other) * 2 + (d - 1)) * d / 2 else: c = my * (my - 1) / 2 if TEST: return c, (N - 1) * (N - 2) return float(c) / (N - 1) / (N - 2) def _test(): global TEST TEST = True assert prob_lt(3, 5, 10) == _prob_lt(3, 5, 10) assert prob_lt(3, 6, 10) == _prob_lt(3, 6, 10) assert prob_lt(6, 6, 10) == _prob_lt(6, 6, 10) assert prob_gt(3, 5, 10) == _prob_gt(3, 5, 10) assert prob_gt(3, 6, 10) == _prob_gt(3, 6, 10) assert prob_gt(6, 6, 10) == _prob_gt(6, 6, 10) if __name__ == "__main__": _test()