Every year on Christmas, we like many other, exchange gifts within the family. We decided that instead of everyone giving presents to everyone (adults), we decide via raffle, who gifts whom (children are not included in this scheme of things).
We are four couples (8 - participants in the raffle). The rules are simple
- Couples are not suppose to choose each other. That is, I am not allowed to gift my partner. The rule applies to all.
- An individual cannot choose him/her self for present. It must be always someone else.
- An individual once chosen as gift giver, will not be chosen again as a gift giver.
- An individual once receives a gift, shall not receive a gift from someone else again.
Thus every year, we have a list of pairs (gift giver, gift receiver) i.e. 8 persons give away 8 presents and 8 persons receive presents.
Based on these rules, I wanted to find out how many (UNIQUE) Sets of (List of) pairs I can get. I tried to find out permutation/combinations with restrictions but I could not determine a general form.
So I wrote some code. A set of (list of) pairs for any given year is given as below:
[[Angelina, Camilla], [Brad, David], [Camilla, Rita], [David, Tom], [Leo, Brad], [Neil, Leo], [Rita, Angelina], [Tom, Neil]]
where Angelina gifts Camila, Brad gifts David so and so forth
My strategy is that i generate these combinations randomly and I do the same process for 100,000 iterations. After every iteration, I add this Set of lists, into another Set, so that I get unique combinations i.e.
[[Angelina, Camilla], [Brad, David], [Camilla, Rita], [David, Tom], [Leo, Brad], [Neil, Leo], [Rita, Angelina], [Tom, Neil]]
[[Angelina, Camilla], [Brad, David], [Camilla, Rita], [David, Tom], [Leo, Brad], [Neil, Leo], [Rita, Angelina], [Tom, Neil]]
such repetitions are excluded.
However atleast one pair change is fine and considered as a candidate to be used.
[[Angelina, Camilla], [Brad, David], [Camilla, Rita], [David, Tom], [Leo, Brad], [Neil, Leo], [Rita, Angelina], [Tom, Neil]]
[[Angelina, Neil], [Brad, David], [Camilla, Rita], [David, Tom], [Leo, Brad], [Neil, Leo], [Rita, Angelina], [Tom, Camilla]]
According to my program, exact 4752 combinations are available. (phew am fine for next 4 millennia) I want to know how can I simply calculate this number with a mathematical form.
Extra One of these years, one of the family member complained, that the person he/she gifted, was the same person from whom he/she also received a gift. So I made changes to this code, such that such combinations are also excluded,
Then the number of combinations became 2652. How can I calculate this number?
I would really like understand computing such permutations/combinations mathematically. I tried it on paper but couldn't do it. I would like to know this so that in future when there are more than 4 couples, i can simply calculate what it means.