santa.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import random
  4. DONT_PAIR = [('blazey', 'tyler')]
  5. EVERYONE = ['tyler', 'shawnie', 'lillian', 'mike', 'blazey']
  6. MATCHES = EVERYONE[:]
  7. def find_match(person, dont_match):
  8. """Match a person with another person."""
  9. match = random.choice(MATCHES)
  10. if match in dont_match or match == person:
  11. if len(MATCHES) == 1:
  12. msg = 'Can\'t match %s --> %s; try this again'
  13. raise RuntimeError(msg, person, match)
  14. return find_match(person, dont_match)
  15. MATCHES.pop(MATCHES.index(match))
  16. print("%s ---> %s" % (person, match))
  17. return (person, match)
  18. if __name__ == '__main__':
  19. final_pairing = []
  20. for person in EVERYONE:
  21. for pairs in DONT_PAIR:
  22. dont_match = []
  23. if person in pairs:
  24. for match in pairs:
  25. if match == person:
  26. continue
  27. dont_match.append(match)
  28. final_pairing.append(find_match(person, dont_match))
  29. print(final_pairing)