My solution to the Quiz #2 is at http://phrogz.net/RubyLibs/quiz/2/
The general approach is:
a) Create a randomized array of Person objects (having parsed the
input).
b) Turn the array into a circular list, and separate any adjacent
family members.
c) Send email (or, if $DEBUG is set, spit out a message), treating
adjacent pairs in the list as giver/receivers.
I initially wrote it treating the array as a circular list, but then
decided I wanted a real circular list class. It's not well tested yet,
but if you like, the Ouroboros class I created is free for the horking.
(It's in the above url, as well as documented and available in main
http:/phrogz.net/RubyLibs/)
I thought I had a better, less-hackish solution than the
pseduo-bubble-sort method I used to separate adjacent duplicates. I
sorted people into family bins, randomized the families, and then
pulled people out from one bin at a time. The benefit was supposed to
be better family separation (to limit occurrances of John Doe from
giving to Bob Smith who gave right back to Jane Doe). Unfortunately, I
didn't think of the case of a single many-member family overpowering
the pool, where early even distribution ends up with only members from
that family left at the end.
I was thinking about weighting my choices by the number of people in
each bin, but since the above solution works, I decided to scrap it.
The interesting thing about this quiz is...my extended family does the
same thing, and up until now no one had thought to automate the
no-same-family rule. The list of members was randomized in excel (much
like Ruby: sort names by an adjacent random number column) and then the
list manually massaged to ensure no family members were adjacent.
I'd never worked with STDIN or SMTP before, so this was a great
exercise for me. Looking forward to looking through other's solutions.
Thanks again for a fun quiz!
--
(-, /\ \/ / /\/