Created
October 10, 2021 07:26
-
-
Save sjbitcode/8be941345b08b55c6d84065464352101 to your computer and use it in GitHub Desktop.
Secret Santa script (draft)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Author
sjbitcode
commented
Oct 10, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment