Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Perform an in shuffle on a list
ResourceFunction["InShuffle"][list] performs an in shuffle on list. | |
ResourceFunction["InShuffle"][list,n] performs n in shuffles on list. |
Perform an in shuffle on a list of 10 items:
In[1]:= | ![]() |
Out[1]= | ![]() |
Perform an in shuffle 3 times to a list:
In[2]:= | ![]() |
Out[2]= | ![]() |
Confirm that this is the same:
In[3]:= | ![]() |
Out[3]= | ![]() |
The list can contain expressions of different type:
In[4]:= | ![]() |
Out[4]= | ![]() |
Create a sorted deck of cards:
In[5]:= | ![]() |
Out[5]= | ![]() |
Shuffle the deck once:
In[6]:= | ![]() |
Out[6]= | ![]() |
The original is obtained after 52 shuffles:
In[7]:= | ![]() |
Out[7]= | ![]() |
An in shuffle on a list of length 2 can be seen as swapping the elements or reversing the list:
In[8]:= | ![]() |
Out[8]= | ![]() |
Figure out after how many in shuffles a list of size n returns to its original order:
In[9]:= | ![]() |
For lists of even length, the number of shuffles to return to the original order is known analytically:
In[10]:= | ![]() |
Out[10]= | ![]() |
In[11]:= | ![]() |
Out[11]= | ![]() |
Visualize how the positions of items are changed for a list of length 21 in the form of a Graph:
In[12]:= | ![]() |
Confirm that 6 nested in shuffles returns the list of 21 items to the original order:
In[13]:= | ![]() |
0 iterations returns the original list:
In[14]:= | ![]() |
Out[14]= | ![]() |
Plot how many in shuffles are needed to return to the original order for a list of length n:
In[15]:= | ![]() |
Out[17]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License