# Scheduling a chess tournament

### Introduction

Right now I'm participating a chess tournament. I got inspired by the tournament schedule. Right now, I'm in a competition with three other players. That means with the four of us, we are playing 3 rounds. The schedule goes as following:

Round 1: 1-4 3-2
Round 2: 3-4 2-1
Round 3: 1-3 4-2

This is also known as Round Robin. Also, this is a valid schedule. We say that a schedule is valid, when it satisfies the following conditions:

• Every player plays once against another player.
• 1-2 means that player 1 has white. Every player has or (N / 2 - 0.5) or (N / 2 + 0.5) times white, with N being the amount of rounds.

For example, in the above example, there are 3 rounds. So N = 3. As you can see, the amount of rounds equals the amount of players - 1. A player has either

• N / 2 - 0.5 = 1 time white, or
• N / 2 + 0.5 = 2 times white.

In the above example:

• player 1 has 2 times white,
• player 2 has 1 time white,
• player 3 has 2 times white,
• player 4 has 1 time white.

Given an even integer > 1 representing the amount of players in the competition, output the tournament schedule.

### Test cases:

Input = 4, that means N = 3

Input:     Output:
4          1-4 3-2
3-4 2-1
1-3 4-2

Input = 10, that means N = 9

Input:     Output:
10         1-10  2-9  3-8  4-7  5-6
10-6  7-5  8-4  9-3  1-2
2-10  3-1  4-9  5-8  6-7
10-7  8-6  9-5  1-4  2-3
3-10  4-2  5-1  6-9  7-8
10-8  9-7  1-6  2-5  3-4
4-10  5-3  6-2  7-1  8-9
10-9  1-8  2-7  3-6  4-5
5-10  6-4  7-3  8-2  9-1

Input = 12, that means N = 11

Input:     Output:
12         1-14    2-13   3-12   4-11   5-10   6-9    7-8
14-8    9-7    10-6   11-5   12-4   13-3   1-2
2-14    3-1    4-13   5-12   6-11   7-10   8-9
14-9    10-8   11-7   12-6   13-5   1-4    2-3
3-14    4-2    5-1    6-13   7-12   8-11   9-10
14-10   11-9   12-8   13-7   1-6    2-5    3-4
4-14    5-3    6-2    7-1    8-13   9-12   10-11
14-11   12-10  13-9   1-8    2-7    3-6    4-5
5-14    6-4    7-3    8-2    9-1    10-13  11-12
14-12   13-11  1-10   2-9    3-8    4-7    5-6
6-14    7-5    8-4    9-3    10-2   11-1   12-13
14-13   1-12   2-11   3-10   4-9    5-8    6-7
7-14    8-6    9-5    10-4   11-3   12-2   13-1

Of course, the extra whitespaces I used between the numbers is optional but not necessary. You may output it in any form you like, as long as it's readable.

Note: The above examples aren't just the only valid outputs. There certainly are more valid outputs.

This is , so the submission with the least amount of bytes wins!

• I think that validity is underspecified. In particular, shouldn't it require that the number of rounds is one less than the number of players? Jan 16, 2016 at 12:03
• @PeterTaylor Yes, I forgot to mention that. I have edited it in the question Jan 16, 2016 at 19:34
• Do players have to be numbered 1 to N, or can they be numbered 0 to N-1? Jan 16, 2016 at 20:48
• @steveverrill Whatever fits best for you. Jan 16, 2016 at 20:59
• Do you have to separate the rounds in the outputs or is 1-4 3-2 3-4 2-1 1-3 4-2 for n=4 a valid output? Jan 16, 2016 at 22:00

# Python 2, 200 186 Bytes

n=input()
t=range(2,n+1)
for k in t:
s=[1]+t
c=[[s[x],s[-x-1]] for x in range(n/2)]
if k%2:c[0].reverse()
t=t[-1:]+t[:-1]
print"\t".join(["-".join([str(y) for y in x]) for x in c])

Example output:

$python chess.py 4 1-4 2-3 3-1 4-2 1-2 3-4$ python chess.py
10
1-10    2-9     3-8     4-7     5-6
9-1     10-8    2-7     3-6     4-5
1-8     9-7     10-6    2-5     3-4
7-1     8-6     9-5     10-4    2-3
1-6     7-5     8-4     9-3     10-2
5-1     6-4     7-3     8-2     9-10
1-4     5-3     6-2     7-10    8-9
3-1     4-2     5-10    6-9     7-8
1-2     3-10    4-9     5-8     6-7

$python chess.py 14 1-14 2-13 3-12 4-11 5-10 6-9 7-8 13-1 14-12 2-11 3-10 4-9 5-8 6-7 1-12 13-11 14-10 2-9 3-8 4-7 5-6 11-1 12-10 13-9 14-8 2-7 3-6 4-5 1-10 11-9 12-8 13-7 14-6 2-5 3-4 9-1 10-8 11-7 12-6 13-5 14-4 2-3 1-8 9-7 10-6 11-5 12-4 13-3 14-2 7-1 8-6 9-5 10-4 11-3 12-2 13-14 1-6 7-5 8-4 9-3 10-2 11-14 12-13 5-1 6-4 7-3 8-2 9-14 10-13 11-12 1-4 5-3 6-2 7-14 8-13 9-12 10-11 3-1 4-2 5-14 6-13 7-12 8-11 9-10 1-2 3-14 4-13 5-12 6-11 7-10 8-9 Or 135 Bytes, by using a less pretty (but still readable) output: ... print c Which produces something like:$ python chess.py
4
[[1, 4], [2, 3]]
[[3, 1], [4, 2]]
[[1, 2], [3, 4]]
• The less pretty answer is also a valid submission. So this is 135 bytes :) Jan 17, 2016 at 18:38
• I'd upvote you if you added a human explanation of your algorithm. Jan 18, 2016 at 9:39