-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
65 lines (52 loc) · 2.23 KB
/
Copy pathtest.py
File metadata and controls
65 lines (52 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def generate_round_robin_schedule_odd(teams):
"""Generate a round-robin schedule for an odd number of teams with alternating home and away games."""
if len(teams) % 2 == 1:
teams.append("N/A") # Add a bye team for even number of teams
num_rounds = len(teams) - 1
num_matches_per_round = len(teams) // 2
schedule = []
for round in range(num_rounds):
round_matches = []
for match in range(num_matches_per_round):
if round % 2 == 0: # Alternate home and away
home = teams[match]
away = teams[-(match + 1)]
else:
away = teams[match]
home = teams[-(match + 1)]
# Ensure the bye team is always away
if home == "N/A":
home, away = away, home
round_matches.append((home, away))
teams.insert(1, teams.pop())
schedule.append(round_matches)
return schedule
def generate_round_robin_schedule_even(teams):
"""Generate a round-robin schedule for an even number of teams with alternating home and away games."""
if len(teams) % 2 != 0:
teams.append("N/A") # Add a bye team for odd number of teams
num_rounds = len(teams) - 1
num_matches_per_round = len(teams) // 2
schedule = []
for round in range(2 * num_rounds): # Double the rounds for home and away
round_matches = []
for match in range(num_matches_per_round):
if round % 2 == 0: # Alternate home and away for first half
home = teams[match]
away = teams[-(match + 1)]
else: # Reverse home and away for the second half
away = teams[match]
home = teams[-(match + 1)]
round_matches.append((home, away))
if round < num_rounds - 1: # Don't rotate in the last round of the first half
teams.insert(1, teams.pop())
schedule.append(round_matches)
return schedule
# Example usage
teams = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
schedule = generate_round_robin_schedule_odd(teams)
for i, round in enumerate(schedule, 1):
print(f"Round {i}:")
for match in round:
print(f"{match[0]} vs {match[1]}")
print("")