import numpy
import tqdm
T1 = ["ESP", "GER", "ITA", "POR", "ENG", "UKR", "FRA", "RUS"]
T2 = ["ESP", "ESP", "ESP", "ENG", "ENG", "GER", "POR", "FRA"]
T3 = ["ENG", "ENG", "ITA", "ITA", "SUI", "GRE", "BEL", "TUR"]
T4 = ["GER", "SCO", "RUS", "POR", "CYP", "NED", "SLO", "AZE"]
def make_draw():
T1R = numpy.random.permutation(T1)
T2R = numpy.random.permutation(T2)
T3R = numpy.random.permutation(T3)
T4R = numpy.random.permutation(T4)
draw = numpy.array([T1R, T2R, T3R, T4R])
return draw
def is_valid(draw, country_protection=True):
if country_protection:
return all(len(numpy.unique(draw[:,i]))==4 for i in range(draw.shape[1]))
else:
return True
def is_good(draw):
return any(all(c not in draw[:,i] for c in ("ESP", "GER", "ENG")) for i in range(draw.shape[1]))
# some testing:
for i in range(5):
draw = make_draw()
while not is_valid(draw):
draw = make_draw()
print(draw)
print("Good: %s" % is_good(draw))
def run(num_trials, country_protection):
count = valid = good = 0
for _ in tqdm.tqdm(xrange(int(num_trials))):
draw = make_draw()
count += 1
if is_valid(draw, country_protection):
valid += 1
if is_good(draw):
good += 1
print("count=%d" % count)
print("valid=%d" % valid)
print("good=%d" % good)
print("%d/%d=%f" % (good, valid, float(good)/float(valid)))
# 1 mio trials, with country protection
run(1e6, True)
# 1 mio trials, without country protection
run(1e6, False)