Created
February 7, 2019 16:26
-
-
Save neila/1ad83a8beacaf7cd52efb26929dce32e to your computer and use it in GitHub Desktop.
CS110 4.2 Preclass
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 | |
import numpy as np | |
def hatproblem(people): | |
hats = [i for i in range(1,people+1)] | |
hatsreplica = [i for i in range(1,people+1)] | |
random.shuffle(hatsreplica) | |
count = 0 | |
for i in range(len(hats)): | |
if hats[i] == hatsreplica[i]: | |
count += 1 | |
return count | |
list = [] | |
for i in range(1000): | |
list.append(hatproblem(i)) | |
print(np.mean(list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment