Guest User

Untitled

a guest
Jun 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. require 'enumerator'
  2. require 'pp'
  3.  
  4. num_teams = ARGV.first.to_i
  5. teams = *1..num_teams
  6. games = teams.combination(2).to_a
  7. slots = Array.new(num_teams-1) { [] }
  8. taken = Array.new(num_teams-1) { [] }
  9. games.each { |a,b|
  10. slots.each_with_index { |slot, i|
  11. unless taken[i][a] || taken[i][b]
  12. slot << [a,b]
  13. taken[i][a] = true
  14. taken[i][b] = true
  15. break
  16. end
  17. }
  18. }
  19.  
  20. p *slots
Add Comment
Please, Sign In to add comment