Function Repository Resource:

MongeanShuffle

Source Notebook

Perform a Mongean shuffle on a list

Contributed by: Katja Della Libera

ResourceFunction["MongeanShuffle"][list]

shuffles the elements in list according to Monge’s shuffle.

ResourceFunction["MongeanShuffle"][list,n]

repeats Monge’s shuffle n times.

Details and Options

The Mongean shuffle is defined as taking the cards from a deck and shuffling them by forming a new deck, alternating between putting the cards from the old deck on the top and bottom of the new deck.
The Mongean shuffle is also called Monge’s shuffle.

Examples

Basic Examples (1) 

Shuffle the list of integers up to 10:

In[1]:=
ResourceFunction["MongeanShuffle"][Range[10]]
Out[1]=

Scope (3) 

Shuffle a list multiple times:

In[2]:=
ResourceFunction["MongeanShuffle"][Take[Alphabet[], 10], 3]
Out[2]=

Confirm that this is the same as applying MongeanShuffle three times:

In[3]:=
ResourceFunction["MongeanShuffle"][
 ResourceFunction["MongeanShuffle"][
  ResourceFunction["MongeanShuffle"][Take[Alphabet[], 10]]]]
Out[3]=

For different lengths of lists, different numbers of shuffles will return them to the original ordering:

In[4]:=
ResourceFunction["MongeanShuffle"][Range[10], 6]
Out[4]=
In[5]:=
ResourceFunction["MongeanShuffle"][Range[15], 14]
Out[5]=
In[6]:=
ResourceFunction["MongeanShuffle"][Range[20], 10]
Out[6]=

Lists of odd length will take the same number of Monge’s shuffles to return to their original ordering as the list of even length preceding them:

In[7]:=
ResourceFunction["MongeanShuffle"][Range[11], 6]
Out[7]=
In[8]:=
ResourceFunction["MongeanShuffle"][Range[14], 14]
Out[8]=
In[9]:=
ResourceFunction["MongeanShuffle"][Range[21], 10]
Out[9]=

Properties and Relations (3) 

The following visualizes how the ordering of the list shifts:

In[10]:=
edges = Thread[
   Range[20] -> Ordering[ResourceFunction["MongeanShuffle"][Range[20]]]];
Graph[edges, VertexLabels -> "Name"]
Out[11]=
In[12]:=
edges = Thread[
   Range[22] -> Ordering[ResourceFunction["MongeanShuffle"][Range[22]]]];
Graph[edges, VertexLabels -> "Name"]
Out[13]=

Visualize the recurring pattern when shuffling lists of different length:

In[14]:=
Table[Column[{n, ArrayPlot[
    Table[ResourceFunction["MongeanShuffle"][Range[n], x]/n, {x, 0, 20}]]}], {n, 10, 20}]
Out[14]=

Another way to visualize the movement of each item is through a simple ListPlot:

In[15]:=
ListPlot[Callout /@ ResourceFunction["MongeanShuffle"][Range[10]]]
Out[15]=

The same list shuffled with two iterations of MongeanShuffle:

In[16]:=
ListPlot[Callout /@ ResourceFunction["MongeanShuffle"][Range[10], 2]]
Out[16]=

Neat Examples (2) 

Use ResourceFunction["PlayingCardGraphics"] to visualize a sorted deck of cards:

In[17]:=
ResourceFunction["PlayingCardGraphic"][Range[52], "CardSpreadAngle" -> 0, "CardOffset" -> {0.4, 0}]
Out[17]=

Shuffle the same deck of cards using two iterations of MongeanShuffle and visualize the result:

In[18]:=
ResourceFunction["PlayingCardGraphic"][
 ResourceFunction["MongeanShuffle"][Range[52], 2], "CardSpreadAngle" -> 0, "CardOffset" -> {0.4, 0}]
Out[18]=

Version History

  • 1.0.0 – 16 August 2019

Related Resources

License Information