Skip to content

Instantly share code, notes, and snippets.

@sjbitcode
Created October 10, 2021 07:26
Show Gist options
  • Save sjbitcode/8be941345b08b55c6d84065464352101 to your computer and use it in GitHub Desktop.
Save sjbitcode/8be941345b08b55c6d84065464352101 to your computer and use it in GitHub Desktop.
Secret Santa script (draft)
from itertools import permutations
from random import choice as randchoice
og_names = ['a', 'b', 'c', 'd'] # secret santa choices
names, recipients = [], []
def set_names():
global names
global recipients
names = og_names[:]
recipients = names[:] # who gets a secret santa
set_names()
matches = {}
ALL_MATCHED = False
while not ALL_MATCHED:
assert ALL_MATCHED == False
print('\n🎄 ---------- Start matching!!! ---------- 🎄\n\n')
for i in range(len(names)):
recipient = randchoice(recipients)
print(f'Finding secret santa for recipient {recipient}')
without_recipient = names
if recipient in names:
without_recipient = names[:names.index(recipient)] + names[names.index(recipient) + 1:]
if not without_recipient:
print('Oops! Have to reshuffle!\n')
matches.clear()
set_names()
break
secret_santa = randchoice(without_recipient)
names.pop(names.index(secret_santa))
print(f'Found match {secret_santa} for recipient {recipient}')
matches[recipient] = secret_santa
recipients.pop(recipients.index(recipient)) # Remove, since this person was matched successfully
print(f'Remaining recipients are {recipients}')
print(f'Remaining secret santas are {names}\n')
if not recipients and not names:
ALL_MATCHED = True
print(matches)
@sjbitcode
Copy link
Author

Screen Shot 2021-10-10 at 3 23 18 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment