Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 86007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:10:43+00:00 2026-05-10T22:10:43+00:00

Every Christmas we draw names for gift exchanges in my family. This usually involves

  • 0

Every Christmas we draw names for gift exchanges in my family. This usually involves mulitple redraws until no one has pulled their spouse. So this year I coded up my own name drawing app that takes in a bunch of names, a bunch of disallowed pairings, and sends off an email to everyone with their chosen giftee.

Right now, the algorithm works like this (in pseudocode):

function DrawNames(list allPeople, map disallowedPairs) returns map     // Make a list of potential candidates     foreach person in allPeople         person.potentialGiftees = People         person.potentialGiftees.Remove(person)         foreach pair in disallowedPairs             if pair.first = person                person.Remove(pair.second)      // Loop through everyone and draw names     while allPeople.count > 0         currentPerson = allPeople.findPersonWithLeastPotentialGiftees         giftee = pickRandomPersonFrom(currentPerson.potentialGiftees)         matches[currentPerson] = giftee         allPeople.Remove(currentPerson)         foreach person in allPeople             person.RemoveIfExists(giftee)      return matches 

Does anyone who knows more about graph theory know some kind of algorithm that would work better here? For my purposes, this works, but I’m curious.

EDIT: Since the emails went out a while ago, and I’m just hoping to learn something I’ll rephrase this as a graph theory question. I’m not so interested in the special cases where the exclusions are all pairs (as in spouses not getting each other). I’m more interested in the cases where there are enough exclusions that finding any solution becomes the hard part. My algorithm above is just a simple greedy algorithm that I’m not sure would succeed in all cases.

Starting with a complete directed graph and a list of vertex pairs. For each vertex pair, remove the edge from the first vertex to the second.

The goal is to get a graph where each vertex has one edge coming in, and one edge leaving.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:10:44+00:00Added an answer on May 10, 2026 at 10:10 pm

    Just make a graph with edges connecting two people if they are allowed to share gifts and then use a perfect matching algorithm. (Look for ‘Paths, Trees, and Flowers’ for the (clever) algorithm)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Every time I create an object that has a collection property I go back
Every One Here When i update my ADT plugin to ADT 16 i get
Every thing was fine and i was able to run this JSP project, suddenly
Hello I'm making Christmas card on flash and I put some snowflakes from this
I want to run a php script on christmas that will email my family
First of all Merry Christmas to everyone!!! Currently I have a NSArray that has
For some reason...maybe looking at too many different examples...this is one of those things
every one i have developed a application in C# for recieving SMS using AT
Every InfringementEntity has a type. foreach (InfringementEntity ie in _infCol.InfCollection.Select(r=>r).Distinct()) { InfringementLodgementEntity.InfringementCollection.InfCollection.Add(ie); } InfringementLodgementCollection.InfringementLodgementEntities
every one know the famous hanoi prolog and you can find it HERE and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.