Secret Santa 2.0

Are you organizing a Secret Santa gift exchange this holiday season? Pulling names out of a hat is sooo luddite. Jason Frey tweeted this 98-character Ruby script that will randomly pair up participants:

Let’s try it out in a Rails console:

>> names = %w{Alice Bob Charlie David Eve}
=> ["Alice", "Bob", "Charlie", "David", "Eve"]
>> names.dup.shuffle.each_with_object({}) {|n, h| h[n] = names.find {|m| m != n}; names.delete(h[n])}
=> {"Bob"=>"David", "David"=>"Alice", "Alice"=>"Bob", "Charlie"=>"Eve", "Eve"=>"Charlie"}

Someone should really turn this into a webapp.

Happy Holidays!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>