On Tue, Nov 27, 2001 at 02:56:16PM -0800, Jeremy Zawodny wrote:
> Since it's the holiday season, someone recently asked me if I could
> hack out a quick script to setup a "scecret santa" system.  The basic
> idea was this:
> 
>     Feed a script a bunch of e-mail addresses.  The script will assign
>     each person (address) the address of someone they should give a
>     gift to.  Each person only gives one gift and receives one gift.
>     Of course, nobody will give a gift to themselves.  (It should also
>     e-mail everyone automatically so that the person running the
>     script doesn't even know the outcome--but I didn't worry about
>     that part at all.)
> 
> What I managed to hack out was rather ugly.  I'm unhappy with it.
> It just didn't feel like the *right* solution, since it had some odd
> logic in it.  That fact that I was watching TV at the time probably
> didn't help.
> 
> Anyone done this before and come up with something they think is
> particularly elegant or clever?

I would probably put all the addresses into an array, shuffle the array
(see perldoc -q shuffle), and then assign each address to the next address
in the array, wrapping around at the end.

In addition to being quick and easy, it also gives you a nice big circle.
:)

Ronald

Reply via email to