Skip to content

Instantly share code, notes, and snippets.

@ih84ds
ih84ds / round-robin.py
Last active October 11, 2023 17:16
Generate Round Robin Schedule with Balanced Home/Away in Python
def create_balanced_round_robin(players):
""" Create a schedule for the players in the list and return it"""
s = []
if len(players) % 2 == 1: players = players + [None]
# manipulate map (array of indexes for list) instead of list itself
# this takes advantage of even/odd indexes to determine home vs. away
n = len(players)
map = list(range(n))
mid = n // 2
for i in range(n-1):