【发布时间】:2013-11-24 11:46:46
【问题描述】:
我正在尝试制作一个 python 脚本来计算一些赢/输机会。 为此,我试图从输赢中找出所有可能的组合(K 是赢得比赛所需的胜利次数):
for combination in itertools.product(['W','L'], repeat=(K*2)-1):
if ((combination.count('L') < K) and (combination.count('W') == K)):
#calculate the chance of this situation happening
由于某种原因,这可以正常工作,直到重复变得很大(例如,如果 K=25) 有人可以给我一些关于如何解决这个问题的指示吗?
【问题讨论】:
-
答案在于数学而不是代码。
标签: python probability product itertools