Adam Monsen

August 21, 2010

Lazy Programmer Automates Christmas Gift Exchange

Filed under: Default — Tags: , , — adam @ 8:52 pm PST

Every year my family does a gift exchange. Names are chosen out of a hat to randomly assign pairs. Certain rules are followed:

  1. give to a different person than last year
  2. partners can’t be nuclear family members (or bf/gf/so/etc.)
  3. can’t choose yourself
  4. participants give one gift only
  5. participants receive one gift only

I decided to give it the old college try in Python. Drawing names following the rules certainly posed more of a challenge than I anticipated! But I think I figured it out. At least, I figured out the “lazy programmer” way to solve it, not the statistician/np-complete/combinatorial/elegant mathy way to solve it.
(more…)

Powered by WordPress