Skip to content

Instantly share code, notes, and snippets.

@neila
Created February 7, 2019 16:26
Show Gist options
  • Save neila/1ad83a8beacaf7cd52efb26929dce32e to your computer and use it in GitHub Desktop.
Save neila/1ad83a8beacaf7cd52efb26929dce32e to your computer and use it in GitHub Desktop.
CS110 4.2 Preclass
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