Menu

How to Prove a Secret Santa Draw Is Possible Before Sending Invitations
📰

How to Prove a Secret Santa Draw Is Possible Before Sending Invitations

DEV Community·Han Lou·about 10 hours ago
#2QRcywuX
#dev#recipient#giver#draw#every
Reading 0:00
15s threshold

A Secret Santa draw gets difficult as soon as the rules become realistic.

Maybe partners should not draw each other. Maybe nobody should receive the same person as last year. A manager should not draw a direct report. Two people share an address. One participant cannot ship internationally.

The usual implementation is: shuffle the names, reject invalid results, and try again. That works for simple groups, but it cannot answer the organizer's most important question:

Is this rule set possible at all?

A loop that has failed 10,000 times may be unlucky, inefficient, or trapped in an impossible set of constraints. Those are very different situations.

This post shows how to model the draw as a matching problem, detect impossible inputs early, and give an organizer a useful error instead of spinning forever.

1.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.