From: martin.ankerl@... (Martin Ankerl) Date: 2004-10-04T02:19:55+09:00 Subject: Re: [QUIZ] Secret Santas (#2) # This implementation is heavily optimized to be as fast to # implement as possible. Please read the above sentence very # carefull ;-) I have tried to find an implementation # that is as simple to understand as possible, but does work. require 'net/smtp' Person = Struct.new("Person", :firstName, :familyName, :email) # extract people from input stream def readSantas(io) santas = Array.new io.read.scan(/(\S*)\s(\S*)\s\<(\S*)\>/) do |first, family, email| santas.push Person.new(first, family, email) end santas end # get an ordering where each santa gets a person who is # outside his family. This implementation is extremely simple, # as it assumes it is always possible to find a correct solution. # Actally it is so simple that it hurts. I would never use this # in production-level code. def orderPeople(santas) isCorrectlyOrdered = false while !isCorrectlyOrdered # get a random order people = santas.sort_by { rand } # check if the random order does meet the requirements i = 0 i += 1 while i