Skip to content

Instantly share code, notes, and snippets.

@mikeyakymenko
Last active October 21, 2021 15:42
Show Gist options
  • Save mikeyakymenko/369eba0fb4b5e68ea4586b8181b6fc20 to your computer and use it in GitHub Desktop.
Save mikeyakymenko/369eba0fb4b5e68ea4586b8181b6fc20 to your computer and use it in GitHub Desktop.
Robin like schedule
def scheduleMatches(teams, rounds=1):
matches = []
if len(teams) % 2 == 1:
teams.append('None')
teamsNumbers = len(teams)
map = list(range(teamsNumbers))
middle = teamsNumbers // 2
for i in range((teamsNumbers-1)*rounds):
map1 = map[:middle]
map2 = map[middle:]
map2.reverse()
round = []
for j in range(middle):
team1 = teams[map1[j]]
team2 = teams[map2[j]]
if team1 != 'None' and team2 != 'None':
if i % 2 == 1:
round.append((team2, team1))
else:
round.append((team1, team2))
matches.append(round)
map = map[middle:-1] + map[:middle] + map[-1:]
return matches
def schedule_cross_conf(conf_a, conf_b, rounds=1):
matches=[]
size = len(conf_a)
for i in range(size*rounds):
conf_a.reverse()
round = []
for j in range(size):
team_a = conf_a[j]
team_b = conf_b[j]
if i+1 <= size:
if i % 2 == 1:
round.append((team_a, team_b))
else:
round.append((team_b, team_a))
else:
if i % 2 == 1:
round.append((team_b, team_a))
else:
round.append((team_a, team_b))
matches.append(round)
conf_a = conf_a[1:] + conf_a[:1]
conf_b = conf_b[1:] + conf_b[:1]
return matches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment