Santa Problem

We follow a relatively simple 3 step process.

1

First, you need to find out how many unique pairs there can be, by iterating through each participant and sub-iterating the remaining participants.

The below pairs would be output for the participants [a,b,c,d]:

[a,b]

[a,c]

[a,d]

[b,c]

[b,d]

[c,d]

This could also be derrived with the following formula:

2

You will then need to run the list of unique pairs through an 'n choose k' combinational algorithm.

Some of the combinations will contain the same participant multiple times:

[[a,b],[a,c]]

[[a,b],[a,d]]

[[a,b],[b,c]]

[[a,b],[b,d]]

[[a,b],[c,d]]

[[a,c],[a,d]]

[[a,c],[b,c]]

[[a,c],[b,d]]

[[a,c],[c,d]]

[[a,d],[b,c]]

[[a,d],[b,d]]

[[a,d],[c,d]]

[[b,c],[b,d]]

[[b,c],[c,d]]

[[b,d],[c,d]]

3

As there are combinations containing the same participant multiple times, you need to remove these by filtering the list.

You will then be left with a list of all unique combinations of unique pairs:

[[a,b],[c,d]]

[[a,c],[b,d]]

[[a,d],[b,c]]

If you want to know more about the n choose k combinational algorithm, please watch this video.

Please try not to get too excited!

Add everyone who is taking part in secret santa.

I am afraid that at the moment we can only calculate the answer for 14 participants!

Sorry, we can only show 300 of the combinations...

Now we need to remove couples who don't want to be paired.

Add singletons into the Coupletron 3000 to couplify them.

True love. No question!

Look at the happy couple.

It takes two to tango...

Add a potential couple to initiate coupling process.

Once you have coupled everyone, go back to the answer page and re-calculate the answer.