Skip to content

Instantly share code, notes, and snippets.

@danielbonnell
Last active August 29, 2015 14:08
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 danielbonnell/9473dbdb2b7484ad4b38 to your computer and use it in GitHub Desktop.
Save danielbonnell/9473dbdb2b7484ad4b38 to your computer and use it in GitHub Desktop.
Round Robin Challenge
def schedule_tournament(names)
matches = names.product(names)
rounds = []
matches.sort!.each do |sub|
sub.sort!
matches.delete(sub) if sub[0] == sub[1]
end
matches.uniq!
until matches.length == 0
list = names.sort
until list.length == 0
round = []
matches.each do |match|
if list.length % 2 == 0 && list.include?(match[0]) && list.include?(match[1])
round << match
list.delete(match[0])
list.delete(match[1])
matches.delete(match)
elsif list.length % 2 != 0 && list.include?(match[0])
round << match
list.delete(match[0])
matches.delete(match)
end
rounds << round
end
end
end
p rounds.uniq
end
schedule_tournament(['Mrs. Featherbottom', 'Ice the Bounty Hunter', 'Gene Parmesan', 'Buster Bluth'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment