Last active
December 18, 2015 21:29
-
-
Save jColeChanged/5847458 to your computer and use it in GitHub Desktop.
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 | |
def initialize_urn(): | |
reds = ["red" for i in range(50)] | |
blacks = ["black" for i in range(50)] | |
return reds + blacks | |
def get_pair(urn): | |
choice_1 = random.choice(urn) | |
urn.remove(choice_1) | |
choice_2 = random.choice(urn) | |
urn.remove(choice_2) | |
return [choice_1, choice_2] | |
def approximate(): | |
num_trials = 10000 | |
num_draws = 50 | |
trial_results = [] | |
for trial in range(num_trials): | |
num_both = 0 | |
urn = initialize_urn() | |
for draw in range(num_draws): | |
pair = get_pair(urn) | |
if "red" in pair and "black" in pair: | |
num_both += 1 | |
trial_results.append(float(num_both)) | |
average_both = sum(trial_results) / num_trials | |
print average_both | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment