Created
October 9, 2023 14:49
-
-
Save scottmries/00902df5d4865378c76650c94abbbe42 to your computer and use it in GitHub Desktop.
n-team, exactly-one-matchup league generator
This file contains hidden or 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 sys | |
teams = int(input("Input the number of teams")) if len(sys.argv) <= 1 else int(sys.argv[1]) | |
weeks = [] | |
for i in range(teams - 1): | |
week = [] | |
remaining_teams = [*range(teams)] | |
# Always 0 | |
fixed_point = remaining_teams.pop(0) | |
# This is the circle part of the circle algorithm, and just position the elements conventiently for array methods | |
wrapped_array = remaining_teams[i:] + remaining_teams[:i] | |
opponent = wrapped_array.pop(0) | |
week.append((fixed_point, opponent)) | |
# For odd teams sizes, the last team will just be unmatched. | |
# This is equivalent to pairing it with the "Bye" team and discarding it | |
while len(wrapped_array) > 1: | |
week.append((wrapped_array.pop(0), wrapped_array.pop())) | |
weeks.append(week) | |
print(weeks) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment