Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Give all the ways the numbers 1, 2, …, n can be scrambled completely
ResourceFunction["Derangements"][n] gives all lists that are rearrangements of {1,2,…,n} such that no element appears in its original position. |
In the following two lists, no element appears in its original place:
| In[1]:= |
| Out[1]= |
Here is the next case, condensed:
| In[2]:= |
| Out[2]= |
The number of lists grows with n!/e:
| In[3]:= |
| Out[3]= |
In fact the number of derangements is given by the built-in subfactorial function:
| In[4]:= |
| Out[4]= |
This work is licensed under a Creative Commons Attribution 4.0 International License