I am trying to solve a mathematics combinatorics question in python in which we select a committee of 5 people with female majority from a group of 8 men and 9 females. My code:
import random
people=["m1", "m2", "m3","m4", "m5", "m6" , "m7","m8", "l1", "l2", "l3", "l4", "l5", "l6", "l7", "l8", "l9"]
combinations=[]
for g in range(10000):
a=random.sample(people, k=5)
b=a.count("l1")
b+=a.count("l2")
b+=a.count("l3")
b+=a.count("l4")
b+=a.count("l5")
b+=a.count("l6")
b+=a.count("l7")
b+=a.count("l8")
b+=a.count("l9")
if b>=3:
if a in combinations:
pass
else:
combinations.append(a)
print (len(combinations))
But for some reason this is including repeated groups. Which means my last few lines of code are not working correctly.
Aucun commentaire:
Enregistrer un commentaire