Created
November 12, 2021 04:50
-
-
Save sergiolucero/fcc57eb5bce7402b6027196e7ab167d9 to your computer and use it in GitHub Desktop.
Simulación CONMEBOL 2021
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 numpy as np | |
from operator import itemgetter | |
LOCAL = 0.5; EMPATE = 0.3; VISITA = 0.2 | |
pos = {'BRA': 33, 'ARG':25, 'ECU':20, 'CHI':16, 'COL':16, | |
'URU': 16, 'PER':14, 'PAR': 12, 'BOL':12 , 'VEN':7 } | |
rem = [('URU','ARG'),('ARG','BRA'), ### CHECK ORDER OF ARG'BRA | |
('BOL','URU'),('VEN','PER'),('COL','PAR'),('ARG','BRA'),('CHI','ECU'), | |
('CHI','ARG'),('COL','PER'),('ECU','BRA'),('PAR','URU'),('VEN','BOL'), | |
('ARG','COL'),('BOL','CHI'),('BRA','PAR'),('PER','ECU'),('URU','VEN'), | |
('ARG','VEN'),('BRA','CHI'),('COL','BOL'),('PAR','ECU'),('URU','PER'), | |
('BOL','BRA'),('CHI','URU'),('ECU','ARG'),('PER','PAR'),('VEN','COL')] | |
class Simula: | |
def __init__(self): | |
self.pos = pos | |
def run(self, nRuns): | |
out = 0 | |
for ix in range(nRuns): | |
pos = self.pos.copy() | |
for match in rem: | |
toss = np.random.rand() | |
rez = (3,0) if toss > LOCAL else (0,3) if toss<VISITA else (1,1) | |
pos[match[0]] += rez[0]; pos[match[1]] += rez[1] | |
# ordenar y clasificar | |
opos = sorted([(k,v) for k,v in pos.items()], key=itemgetter(1)) | |
#print(opos) | |
rk = [k[0] for k in opos[:3]] | |
out = out + 1 if 'CHI' in rk else out | |
print(out/nRuns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment