Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Test whether a permutation is a derangement
ResourceFunction["DerangementQ"][p] tests whether the permutation p is such that no element appears in its original position. |
No elements are in their original places:
In[1]:= | ![]() |
Out[1]= | ![]() |
For even n, the list {n,…,3,2,1} is a derangement:
In[2]:= | ![]() |
Out[2]= | ![]() |
Test if a permutation in disjoint cycle format is a derangement:
In[3]:= | ![]() |
Out[3]= | ![]() |
The chances are about 1 in 3 that a permutation is a derangement:
In[4]:= | ![]() |
Out[4]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License