Created
October 12, 2019 13:03
-
-
Save jejones3141/7ba94a81d6cc546d8a1b139de30b34cd to your computer and use it in GitHub Desktop.
Monte Carlo code to aid with solution of the October 4, 2019 fivethirtyeight.com Riddler Classic problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random, collections | |
def bdaySample(size): | |
sample = collections.Counter() | |
for i in range(size): | |
sample[random.randrange(365)] += 1 | |
return max(sample.values()) | |
def probAtLeast(n, size, nSamples): | |
atLeastN = sum(1 for c in ( | |
bdaySample(size) for i in range(nSamples)) if c >= n) | |
return atLeastN / nSamples |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment