Wolfram Research

Function Repository Resource:

DerangementQ

Source Notebook

Test whether the permutation list is completely scrambled

Contributed by: Wolfram Staff

ResourceFunction["DerangementQ"][p]

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

Examples

Basic Examples

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

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

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

Resource History

See Also

License Information