総当たり戦の日程作成
Posted feedbacks - Python
1日の試合数分のジェネレーターを作って、そこで組み合わせを作成。
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 | from itertools import izip
def matchmake1(team):
for i in xrange(1, team):
yield [1, i + 1]
def matchmake2(i, j, team):
def next_day(k):
while 1:
yield k
k = k + 1 if k < team else 2
for match in izip(next_day(i), next_day(j)):
yield list(match)
def schedule(team):
leagu = [matchmake1(team)]
for i, j in izip(xrange(3, team / 2 + 2), xrange(team, 0, -1)):
leagu.append(matchmake2(i, j, team))
for match in izip(*leagu):
print list(match)
if __name__ == '__main__':
schedule(6)
|


ryugate
#5661()
Rating2/2=1.00
see: カークマンの組分け
[ reply ]