In a tournament with direct elimination where teams are seeded, the first seed team plays the last seed team, the second seed team, play the one before last seed team, etc. I'll use example with 16 teams which gives us the total of 8 matches. So the matches are:
1 - 16
2 - 15
3 - 14
4 - 13
5 - 12
6 - 11
7 - 10
8 - 9
The problem that I'm facing is how to put those matches in the tournament grid/bracket so that assuming that all higher seeded teams win, the final will be seed 1 vs seed 2, semi-finals will be seed 1 vs seed 4, seed 2 vs seed 3 etc. Drawing everything on paper, the example above should look like this in the first round of the tournament:
Match 1: 1 - 16
Match 2: 9 - 8
Match 3: 5 - 12
Match 4: 13 - 4
Match 5: 3 - 14
Match 6: 11 - 6
Match 7: 7 - 10
Match 8: 15 - 2
where winner of Match 1 plays winner of Match 2, winner of Match 3 plays winner of Match 4, etc. What I'm trying to figure out is a formula to calculate the match number for team x given n teams playing in the first round. I actually managed to get some kind of a sequence going but I still can't figure out how to write the formula in one line. Here's what I got for the example above:
Team 1 & Team 16 Match Number: 1
Team 2 & Team 15 Match Number: n
Team 3 & Team 14 Match Number: n/2 + 1
Team 4 & Team 13 Match Number: n/2
Team 5 & Team 12 Match Number: n/2 - n/4 + 1
Team 6 & Team 11 Match Number: n/2 + n/4
Team 7 & Team 10 Match Number: n/2 + n/4 + 1
Team 8 & Team 9 Match Number: n/2 - n/4
Results respectively in match numbers: 1, 8, 5, 4, 3, 6, 7, 2 as intended
Continuing for let's say a tournament with 32 teams the sequence still works:
Team 1 & Team 32 Match Number: 1
Team 2 & Team 31 Match Number: n
Team 3 & Team 30 Match Number: n/2 + 1
Team 4 & Team 29 Match Number: n/2
Team 5 & Team 28 Match Number: n/2 - n/4 + 1
Team 6 & Team 27 Match Number: n/2 + n/4
Team 7 & Team 26 Match Number: n/2 + n/4 + 1
Team 8 & Team 25 Match Number: n/2 - n/4
Team 9 & Team 24 Match Number: n/2 - n/4 - n/8 + 1
Team 10 & Team 23 Match Number: n/2 + n/4 + n/8
Team 11 & Team 22 Match Number: n/2 + n/4 - n/8 + 1
Team 12 & Team 21 Match Number: n/2 - n/4 + n/8
Team 13 & Team 20 Match Number: n/2 - n/4 + n/8 + 1
Team 14 & Team 19 Match Number: n/2 + n/4 - n/8
Team 15 & Team 18 Match Number: n/2 + n/4 + n/8 + 1
Team 16 & Team 17 Match Number: n/2 - n/4 - n/8
Results respectively in match numbers: 1, 16, 9, 8, 5, 12, 13, 4, 3, 14, 11, 6, 7, 10, 15, 2 as intended
Feels like I'm very close to the finish line but I can't get all the numbers in one simple formula. Any help would be greatly appreciated.