元组生日悖论

2024-09-24 22:30:39 发布

您现在位置:Python中文网/ 问答频道 /正文

元组是n

生日问题的等式是:

问题:

For n = 200, write an algorithm (in Python) for enumerating the number of tuples in the sample space that satisfy the condition that at least two people have the same birthday. (Note that your algorithm will need to scan each tuple)

import itertools

print(list(itertools.permutations([0,0,0]))

对于这个问题,我想知道如何在其中插入n?在


Tags: oftheinannumberforthatalgorithm
1条回答
网友
1楼 · 发布于 2024-09-24 22:30:39

“如何让n进入那里”:

n = 200
space = itertools.permutations(bday_pairs, n)

我漏掉了你代码的几个部分:

itertools返回一个列表;您不需要强制它。在

如果n=200,打印这个结果可能不是您想要的;这是一个巨大的列表。在

现在,你所要做的就是建立bday_pairs,所有可能的生日对的列表。为了方便起见,我建议您使用整数1-365。既然你根本没有解决问题的那一部分,我就把这一步留给你。在

您仍然需要进行处理来计算至少有一个匹配生日的集合,这是您尚未解决的另一个问题。但是,我相信上面的代码解决了您所说的问题?在

相关问题 更多 >