Skip to content

Instantly share code, notes, and snippets.

@jejones3141
Created October 12, 2019 13:03
Show Gist options
  • Save jejones3141/7ba94a81d6cc546d8a1b139de30b34cd to your computer and use it in GitHub Desktop.
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
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