Secret Santa - Generating 'valid' permutations

前端 未结 6 811
不思量自难忘°
不思量自难忘° 2021-02-02 08:54

My friends invited me home to play the game of Secret Santa, where we are supposed to draw a lot & play the role of \'Santa\' for a friend in the group.

So, we write

6条回答
  •  有刺的猬
    2021-02-02 09:27

    This does not answer your question about counting the valid derangements, but it gives an algorithm to generate one (which might be what you want) with the following properties:

    1. it guaranties that there is a single cycle in Santa's relationship (if you play at 4, you do not end up with 2 Santa couples --> 2 cycles),
    2. it works efficiently even with very large number of player,
    3. if applied fairly, nobody knows whose who Santa's,
    4. it does not need a computer, only some paper.

    Here the algorithm:

    • Every player writes her/his name on an envelope and puts her/his name in a folded paper in the envelope.
    • One trusted player (for property # 3 above) takes all the envelopes and shuffles them looking at their back side (where no name is written).
    • Once the envelops are shuffled well enough, always looking at the back side, the trusted player moves the paper in each envelope to the following one.
    • After shuffling the envelops again, the envelopes are distributed back to the player whose name is on them, and each player is the Santa of the person whose name is in the envelope.

提交回复
热议问题