Skip to content

Instantly share code, notes, and snippets.

@mikeyakymenko
Last active October 21, 2021 15:42
Show Gist options
  • Select an option

  • Save mikeyakymenko/369eba0fb4b5e68ea4586b8181b6fc20 to your computer and use it in GitHub Desktop.

Select an option

Save mikeyakymenko/369eba0fb4b5e68ea4586b8181b6fc20 to your computer and use it in GitHub Desktop.

Revisions

  1. mikeyakymenko revised this gist Oct 21, 2021. 1 changed file with 28 additions and 1 deletion.
    29 changes: 28 additions & 1 deletion robin_like_schedule.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,30 @@
    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)
    @@ -22,4 +49,4 @@ def schedule_cross_conf(conf_a, conf_b, rounds=1):
    conf_a = conf_a[1:] + conf_a[:1]
    conf_b = conf_b[1:] + conf_b[:1]

    return matches
    return matches
  2. mikeyakymenko created this gist Oct 21, 2021.
    25 changes: 25 additions & 0 deletions robin_like_schedule.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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