Secret Santa Perfect Loop problem 
*

*(n) people put their name in a hat.  

*Each person picks a name out of the hat to buy a gift for.  

*If a person picks out themselves they put the name back into the hat.

*If the last person can only pick themselves then the loop is invalid and either
. start again
. or step back until a valid loop can be reached.


What is the probability that if n is 33 that the chain creates a perfect loop?
An example of a perfect loop where n is 4:  


*

*A gives to B  

*B gives to C  

*C gives to D.  

*D gives to A.    


An example of a valid but not perfect loop where n is 4:


*

*A gives to B  

*B gives to A  

*C gives to D.  

*D gives to C.    


Let $P_N$ be the probability to obtain a perfect loop with $N$ participants.
$ A \rightarrow C \rightarrow B \rightarrow D \rightarrow A $
$ A \rightarrow B \rightarrow D \rightarrow C \rightarrow A $
$ C \rightarrow A \rightarrow B \rightarrow D \rightarrow C $
are perferct loops.
We can see that the second and third one describe the same loop, so we can count the total number of perfect loops by counting all the possible permutations of C, B and D.
In the same manner, we find that the number of perfect loops with N participants is $(N-1)!$
Thus, 
$P_N = \frac{(N-1)!}{n(\Omega)} $
The sample space are all possible loops such as everyone has been asigned a different name than his own, which is in other words, the total number of possible derangments.
The number of derangments of n items, $d(N)$,  is given by
$d(N) = N! \sum_o^N\frac{(-1)^i}{i!}$
And so,
$P_N = \frac{(N-1)!}{d(N)} = \frac{1}{N \sum_o^N\frac{(-1)^i}{i!}} $
For $N = 33$, 
$P_N = \frac{8222838654177922817725562880000000}{3194414033122656019847107490716704992}$
