# Untitled

unknown
plain_text
2 months ago
3.1 kB
4
Indexable
Never
```def league_scheduler(N):
required_match_count = int( (N * (N-1)) / 2 )
max_days = required_match_count
league_schedule_tracker = [""] * max_days
day_match_count_tracker = [0] * max_days

team_match_tracker = [[0 for x in range(N)] for x in range(N)]
day_team_match_tracker = [[0 for x in range(N)] for x in range(max_days)]

print(f"Team  Count: {N}")
# print(f"max_days: {max_days}")
print(f"required_match_count: {required_match_count}")

required_day_count = 0
current_match_count = 0
for day in range(max_days):
for i in range(N):
for j in range(N):
# Cant play against self
if i == j:
team_match_tracker[i][j] = 1
continue

# Already played against each other
if team_match_tracker[i][j] == 1:
continue

if day_team_match_tracker[day][i] == 1 or day_team_match_tracker[day][j] == 1:
continue

# Mark played against each other
team_match_tracker[i][j] = 1
team_match_tracker[j][i] = 1

# Mark team played of this day
day_team_match_tracker[day][i] = 1
day_team_match_tracker[day][j] = 1

current_match_count += 1

league_schedule_tracker[day] += f"T{i+1} v T{j+1} | "
day_match_count_tracker[day] += 1

if current_match_count == required_match_count:
required_day_count = day + 1
break

# print(f"current_day: {day}")
# print(f"current_match_count: {current_match_count}")
continue

if current_match_count == required_match_count:
required_day_count = day + 1
break
if current_match_count == required_match_count:
required_day_count = day + 1
break

print(f"required_day_count: {required_day_count}")
print(f"day_match_count_tracker: {day_match_count_tracker[:required_day_count]}")

# print(f"team_match_tracker: {json.dumps(team_match_tracker, indent=2)}")
# print(f"day_team_match_tracker: {json.dumps(day_team_match_tracker, indent=2)}")

x = 0
for i in range(required_day_count):
x += day_match_count_tracker[i]
# print(day_match_count_tracker[i])
print(f"Average matches per day = {x/required_day_count}")

# for i in range(required_day_count):
#     print()
#     print(f"DAY {i+1} Match schedule:")
#     print(f"day_match_count = {day_match_count_tracker[i]}")
#     for item in league_schedule_tracker[i].split("|"):
#         if item.strip():
#             print(f" -> {item.strip()}")

# N = number of teams
for i in range(2, 10):
league_scheduler(i*2)
print()
```