[Niklas Frykholm <niklas / kagi.com>, 2004-10-04 10.49 CEST] > An interesting problem. It seems trivial at first, but when you start to > think about whether a solution is possible or not and in which way you > can assign santas as random as possible, but without painting yourself > into a corner it gets quite complex. Here is a mathematical analysis: [...] I didn't participate, but I thought it was a trivial case of sorting the families by number of members and start giving santas from the most populous down. I should have tested that theory with code, but I didn't have time on the weekend :(. How can it not work? Something like this: (NOT TESTED) Participant = Struct.new :name, :family, :email participants = [] while line = gets line =~ /^(\w+) (\w+) (.*+)$/ participants << Participant.new($1, $2, $3) end families = {} participants.each do |p| families[p.family] ||= [] families[p.family] << p end families = families.values.sort_by{ |a| a.size }.reverse families.each do |family| family.each do |member| idx = rand(participants.size) until participants[idx].family != member.family print member.family, "->", participants[idx].family participants.delete_at idx end end --