-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecret_santa.py
More file actions
41 lines (35 loc) · 1.21 KB
/
secret_santa.py
File metadata and controls
41 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import random
from copy import deepcopy
family = { # name of family member, list of anyone that should be excluded from the family member
'Lucky Watcher': ['Arrogant Contender'],
'Arrogant Contender': ['Lucky Watcher'],
'Tuff Genius': ['Insane Madman'],
'Insane Madman': ['Tuff Genius'],
'Irate Watcher': [],
'Respected Watcher': ['Thunderous Leader'],
'Thunderous Leader': ['Respected Watcher'],
'X-pert Samurai': []
}
secretSanta = dict()
names = list(family.keys())
shuffled = deepcopy(names)
for iteration in range(1000):
random.shuffle(shuffled)
# Traverse givers & receivers with `itertools.pairwise`.
for giver, receiver in zip(names, shuffled):
if receiver in family[giver] or receiver == giver:
secretSanta = dict()
break
else:
secretSanta[giver] = receiver
else:
print(f"Solved in {iteration} iterations")
break
if secretSanta:
sorted_secretSanta = dict(sorted(secretSanta.items()))
print(f'{"Giver":30}{"Reciever"}')
print('------------------------------------------------')
for key, value in sorted_secretSanta.items():
print(f'{key:30}{value}')
else:
print('Program failed. ')