Off topic, not an entry, learning moment

Off topic, not an entry, learning moment

@miccaela’s entry is going to be hard to beat. Gotta love when we see intuitive code and become inspired to break it down. This led to a two part version, of which one part is a reusable helper.

from random import shuffle def discrete_pairs(n): a, b = range(n), [*range(n)] while any(a[i] == b[i] for i in a): shuffle(b) return b def santas_helper_pairs(arr): n = len(arr) dp = discrete_pairs(n) for i in range(n): print(f"{arr[i]} -> {arr[dp[i]]}") office = ['Michael Scott', 'Dwight Schrute', 'Jim Halpert', 'Pam Beesly', 'Jan Levinson', 'Kevin Malone', 'Toby Flenderson', 'Angela Martin', 'Andy Bernard', 'Stanley Hudson', 'Ryan Howard', 'Kelly Kapoor'] santas_helper_pairs(office)

Big thanks for the excellent takeaway from the above entry.

2 Likes

Thank you!! Had a hard time figuring out a way to create a loop to shuffle the list until they weren’t the same person. :sweat_smile:

1 Like

This is so cool!
Nicely done!

1 Like