Created
March 31, 2016 16:16
-
-
Save RobertAKARobin/830375a60296cee17e128dd5daab6ca0 to your computer and use it in GitHub Desktop.
Student matcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
names = [ | |
"Alice", | |
"Bob", | |
"Carol", | |
"David", | |
"Eliza", | |
"Frank", | |
"Gretchen", | |
"Harry", | |
"Irene", | |
"Joe", | |
"Karen", | |
"Luke", | |
"Mary", | |
"Nick", | |
"Olga", | |
"Pete" | |
] | |
numChoices = 5 | |
numPerGroup = 3 | |
peeps = names.map do |name| | |
{ | |
name: name, | |
choices: [], | |
chosenBy: [], | |
matched: false | |
} | |
end | |
peeps.each do |person| | |
choices = peeps.dup | |
choices.delete person | |
names = [] | |
numChoices.times do | |
choice = choices.sample | |
next if person[:choices].include? choice | |
person[:choices].push choice | |
choice[:chosenBy].push person | |
end | |
puts "#{person[:name]} wants #{person[:choices].collect{|c| c[:name]}.join(",")}" | |
end | |
peeps.sort!{|a,b| b[:chosenBy].size <=> a[:chosenBy].size } | |
puts "*" * 10 | |
peeps.each do |person| | |
puts "#{person[:name]} chosen by #{person[:chosenBy].collect{|c| c[:name]}.join(",")}" | |
end | |
puts "*" * 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment