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 97209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:57:38+00:00 2026-05-10T23:57:38+00:00

Ladies and Gents, My best friends and I do a Secret Santa type gift

  • 0

Ladies and Gents,

My best friends and I do a ‘Secret Santa’ type gift exchange every year, this year I’ve been trying to think of a couple of ways to make it interesting. There are six of us involved and I want to design a small program that allows the six of us to rank their preferred gift-recipients from 1 to 5 as well as their preferred gift-givers.

So, let’s say we’re called A, B, C, D, E and F.

A submits two lists:

List 1 – People I would most like to give a present to: B, D, C, F, E

List 2 – People I would most like to recieve a present from: F, D, E, B, C

All six of us will submit both these lists, so I’ll have 12 lists all together. I suppose my question is what is the best algorithm to now go ahead and assign each person a gift recipient?

I thought of something like this:

If two people have both selected each other in their opposing lists (i.e. A most wants to give to B, B most wants to get from A) then I immediately assign A to B. So now A is removed from our list of gift-recipients and B is removed from our pool of gift-givers.

Once I’ve assigned the ‘perfect matches’ I’m kind of lost though, is there an establish algorithm for situations like this? Obviously it’s only for entertainment value but surely there must be a ‘real’ application of something similar? Perhaps timetabling or something?

My Google-fu has failed me but I have a feeling it might just be due my own lack of precision in search terms.

Cheers, (and Happy Holidays I guess), Rob


Update / Part 2

Okay, Ying Xiao came to the rescue by recommending the Gale Shapley Algorithm for the Stable Marriage Problem and I’ve implemented that in Python and it works a treat. However, this is just a thought that occurred to me. I guess within our group of six best friends there are three pairings of ‘extra-best’ friends so I have a feeling we’ll just end up with three pairs of AB, CD, EF and BA, DC, FE in terms of gift giving and recieving.

Is there an algorithm we could design that did take peoples rankings into account but also restricted two people forming a ‘closed group’? That is, if A is assigned to buy a gift for B, B can not be assigned to buy a gift for A? Perhaps I need to solve the Stable roommates problem?

Related questions:

  • Secret santa algorithm.
  • What is the best low-tech protocol to simulate drawing names out of a hat and ensure secrecy?
  • 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-10T23:57:39+00:00Added an answer on May 10, 2026 at 11:57 pm

    The Gale-Shapley algorithm (for the Stable Marriage problem) applies only when each person has a ranked list of all other participants — you may or may not be able to convert your problem to that form (make everyone rank everyone).

    Also, note that the thing it is optimizing for is something different: it tries to find a set of stable marriages, where no pair of people will ‘elope’ because they prefer each other to their current partners. This is not something you care about in your Secret Santa application.

    What you want (depending on your definition of ‘best’) is a maximum-weight bipartite matching, which fixes both the above objections: put the ‘givers’ on one side, the ‘receivers’ on the other (so two copies of each person, in this case), give each edge a weight corresponding to how highly that giver ranks that receiver, and it is now the assignment problem. You can use the Hungarian algorithm for this, or simpler (slower) ones. You can also vary how you assign the weights to optimize for different things (e.g. maximize the number of people who get their first choice, or minimize the worst choice that anyone gets, etc.)

    If you do use the Gale-Shapley stable marriage algorithm, note that it is optimal for the ‘proposers’ (male-optimal and female-pessimal), so be sure to put the ‘givers’ as the ‘proposers’, and not vice versa.

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

Sidebar

Ask A Question

Stats

  • Questions 59k
  • Answers 59k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer print function does that: Print figure or save to specific… May 11, 2026 at 9:02 am
  • added an answer Types are dependent to your initialization: var IsLoggedIn1 = 'true';… May 11, 2026 at 9:02 am
  • added an answer AFAIK, there isn't one right now. But you can make… May 11, 2026 at 9:02 am

Related Questions

Ladies and Gents, My best friends and I do a Secret Santa type gift
Hello again ladies and gents! OK, following on from my other question on ASP.NET

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.