Wolfram Research

Function Repository Resource:

DerangementQ (1.0.0) current version: 1.1.0 »

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]=

Version History

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

Related Resources

License Information