Skip to content

Instantly share code, notes, and snippets.

@codeodor
Created May 1, 2015 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeodor/e894033665a590784d76 to your computer and use it in GitHub Desktop.
Save codeodor/e894033665a590784d76 to your computer and use it in GitHub Desktop.
tournament seeding
teams = (1..16).to_a
# => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
games = (0..7).inject([]){|g, i| g << [teams[i], teams[-i-1]] }
# => [[1, 16], [2, 15], [3, 14], [4, 13], [5, 12], [6, 11], [7, 10], [8, 9]]
# so now, how do I transform that to:
# => [[1, 16], [8, 9], [5, 12], [4, 13], [6, 11], [3, 14], [7, 10], [2, 15]]
# In essence, I have the teams already sorted into the games of who plays who in this round.
# But I want to order the games so they appear next to who will play the winners of this round in the next round.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment