Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'enumerator'
- require 'pp'
- num_teams = ARGV.first.to_i
- teams = *1..num_teams
- games = teams.combination(2).to_a
- slots = Array.new(num_teams-1) { [] }
- taken = Array.new(num_teams-1) { [] }
- games.each { |a,b|
- slots.each_with_index { |slot, i|
- unless taken[i][a] || taken[i][b]
- slot << [a,b]
- taken[i][a] = true
- taken[i][b] = true
- break
- end
- }
- }
- p *slots
Add Comment
Please, Sign In to add comment