Skip to content

Instantly share code, notes, and snippets.

@john-adeojo
Last active January 11, 2022 12:41
Show Gist options
  • Save john-adeojo/bcbef1c446fc7be44a228a44c2b0264d to your computer and use it in GitHub Desktop.
Save john-adeojo/bcbef1c446fc7be44a228a44c2b0264d to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
import random
from itertools import combinations
def simulate_naive(n_teams):
#Simulate a single season'
scores = np.zeros(n_teams, dtype=int)
for i, j in combinations(range(n_teams), 2):
# each pair of teams play twice, each time with 50/50 chance of
# either team winning; the winning team gets three points
scores[i if np.random.rand() < 0.5 else j] += 3
scores[i if np.random.rand() < 0.5 else j] += 3
return scores
# Simulate across multiple seasons
def perfect_competition(n_teams, n_seasons):
df = pd.DataFrame({season: simulate_naive(n_teams) for season in range(n_seasons)})
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment