Last active
December 7, 2019 05:26
-
-
Save mattfitzgerald/552c9385d78197c4bae8754f9b657cea to your computer and use it in GitHub Desktop.
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
# will not pair people with a member of their houshold | |
households = [%w(Jeannie Terry\ Snr), ["Benton"], ["Terry"], %w(Mandy Marcos Elías Mateo), %w(Erin Matt)] | |
households.sort!{|a,b| b.length <=> a.length} | |
names = households.flatten | |
pairs = {} | |
names.each do |name| | |
household = households.find{|h| h.include?(name)} | |
available_names = (names - pairs.values - household) | |
if i == names.length - 2 and available_names.include?(names.last) #inelegant | |
# prevent an unmatchable last pair | |
pairs[name] = names.last | |
else | |
pairs[name] = available_names.sample | |
end | |
puts "#{name.ljust(9)} gives a book to #{pairs[name]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment