您可以在前 7 天进行第一轮循环赛,这样每支球队都会与其他球队交手一次。然后在最后3天,做两个单独的循环赛,让abcd中的队伍再次对战,efgh中的队伍再次对战。更多关于循环赛的信息:
# a table is a simple list of teams
def next_table(table):
return [table[0]] + [table[-1]] + table[1:-1]
# [0 1 2 3 4 5 6 7] -> [0 7 1 2 3 4 5 6]
# a pairing is a list of pairs of teams
def pairing_from_table(table):
return list(zip(table[:len(table)//2], table[-1:len(table)//2-1:-1]))
# [0 1 2 3 4 5 6 7] -> [(0,7), (1,6), (2,5), (3,4)]
# a team is an element of the table
def round_robin(table):
pairing_list = []
for day in range(len(table) - 1):
pairing_list.append(pairing_from_table(table))
table = next_table(table)
return pairing_list
def get_programme():
first7days = round_robin(list('abcdefgh'))
last3days_abcd = round_robin(list('abcd'))
last3days_efgh = round_robin(list('efgh'))
return first7days + [a+e for a,e in zip(last3days_abcd, last3days_efgh)]
print(get_programme())
# [[('a', 'h'), ('b', 'g'), ('c', 'f'), ('d', 'e')],
# [('a', 'g'), ('h', 'f'), ('b', 'e'), ('c', 'd')],
# [('a', 'f'), ('g', 'e'), ('h', 'd'), ('b', 'c')],
# [('a', 'e'), ('f', 'd'), ('g', 'c'), ('h', 'b')],
# [('a', 'd'), ('e', 'c'), ('f', 'b'), ('g', 'h')],
# [('a', 'c'), ('d', 'b'), ('e', 'h'), ('f', 'g')],
# [('a', 'b'), ('c', 'h'), ('d', 'g'), ('e', 'f')],
# [('a', 'd'), ('b', 'c'), ('e', 'h'), ('f', 'g')],
# [('a', 'c'), ('d', 'b'), ('e', 'g'), ('h', 'f')],
# [('a', 'b'), ('c', 'd'), ('e', 'f'), ('g', 'h')]]