Created
December 22, 2015 18:09
-
-
Save willettk/510efcd6ee50de399aa3 to your computer and use it in GitHub Desktop.
Riddler on FiveThirtyEight - Dec 22, 2015
This file contains hidden or 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 | |
import numpy | |
N = 2000 | |
Nt = 100000 | |
times = [] | |
nomatch = 0 | |
for i in range(Nt): | |
my_tasks = [] | |
her_tasks = [] | |
for j in range(N): | |
my_tasks.append(int(random.uniform(0,1)*5+1)) | |
her_tasks.append(int(random.uniform(0,1)*5+1)) | |
mytot = numpy.cumsum(my_tasks) | |
hertot = numpy.cumsum(her_tasks) | |
inds = numpy.arange(N) | |
try: | |
ind = (inds[mytot == hertot])[0] | |
times.append(mytot[ind]) | |
except: | |
nomatch += 1 | |
print "Mean amount of time until we eat: {0:.0f} minutes.".format(numpy.median(times)) | |
print "Median amount of time until we eat: {0:.0f} minutes.".format(numpy.median(times)) | |
print "Never ate within {0} minutes for {1}/{2} trials.".format(N,nomatch,Nt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment