Function Repository Resource:

DerangementQ

Source Notebook

Test whether a permutation is a derangement

Contributed by: Wolfram Staff

ResourceFunction["DerangementQ"][p]

tests whether the permutation p is such that no element appears in its original position.

Details

The permutation can be given in either permutation list or disjoint cyclic format.

Examples

Basic Examples (2) 

No elements are in their original places:

In[1]:=
ResourceFunction["DerangementQ"][{3, 1, 4, 2}]
Out[1]=

For even n, the list {n,,3,2,1} is a derangement:

In[2]:=
ResourceFunction["DerangementQ"][Reverse[Range[12]]]
Out[2]=

Scope (1) 

Test if a permutation in disjoint cycle format is a derangement:

In[3]:=
ResourceFunction["DerangementQ"][
 Cycles[{{1, 15, 4, 10, 2}, {3, 7, 8, 12, 6, 14}, {5, 13, 11, 9}}]]
Out[3]=

Applications (1) 

The chances are about 1 in 3 that a permutation is a derangement:

In[4]:=
Table[ResourceFunction["DerangementQ"][RandomPermutation[12]], {9}]
Out[4]=

Publisher

George Beck

Version History

  • 1.1.0 – 07 February 2022
  • 1.0.0 – 29 May 2019

Related Resources

License Information