Skip to content

Commit

Permalink
Add script to experiment average number of draws needed to get Bob.
Browse files Browse the repository at this point in the history
Intuition says it will be roughly half, and looks to be confirmed here. However,
analysis patterned from Section 5.2 (Indicator Random Variables) of CORMEN3
suggests that it should be ln N. I wonder where my analysis is wrong.
  • Loading branch information
skytreader committed Dec 24, 2018
1 parent f05679e commit 724b915
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions experimental-statistics/exchange-gift/bobfinder.py
@@ -0,0 +1,22 @@
#!/usr/bin/env python3

import random

class BobFinder(object):

def __init__(self, shuffler=random.shuffle):
self.shuffler = shuffler

def find_bob(self, participant_count):
pool = ["Participants %s" % i for i in range(participant_count - 1)]
pool.append("Bob")
self.shuffler(pool)
return pool.index("Bob") + 1

def experiment(participant_count=40, runs=1000):
bob_finder = BobFinder()
bob_posn_sum = sum([bob_finder.find_bob(participant_count) for i in range(runs)])
return bob_posn_sum / runs

if __name__ == "__main__":
print(experiment())

0 comments on commit 724b915

Please sign in to comment.