Function Repository Resource:

OutShuffle

Source Notebook

Perform an out shuffle on a list

Contributed by: Sander Huisman

ResourceFunction["OutShuffle"][list]

performs an out shuffle on list.

ResourceFunction["OutShuffle"][list,n]

performs n out shuffles on list.

Details and Options

An out shuffle is defined as follows: (1) split the list in two halves; and (2) interweave each half of the list starting with the first half, such that every other card comes from the same half of the list.
Here is an example of a list with 10 items:
When the list has an odd length n, the first "half" will be (n+1)/2 long and the second "half" will be (n-1)/2 long:

Examples

Basic Examples (1) 

Perform an out shuffle on a list of 10 items:

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

Scope (2) 

Perform an out shuffle 3 times to a list:

In[2]:=
ResourceFunction["OutShuffle"][Range[10], 3]
Out[2]=

Confirm that this is the same:

In[3]:=
ResourceFunction["OutShuffle"][
 ResourceFunction["OutShuffle"][
  ResourceFunction["OutShuffle"][Range[10]]]]
Out[3]=

The list can contain expressions of different types:

In[4]:=
ResourceFunction["OutShuffle"][{2/3, 3 + 2 I, "Test", \!\(\*
GraphicsBox[{{{}, {}, 
TagBox[
{RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], Opacity[1.], LineBox[CompressedData["
1:eJwlmXk4lN/7x61ZEjPPjJAU7SsppYXuUwlFSokWIWkhSURIKpWQZK9kS4X4
RHZJTpSikKiEopAsYx7rmJksv/O9fn+d63Vd82zv9/u+73Ou0bA/u/e4mIiI
SJaoiMj/VnEsW9ux9upmXun/rwt7SjfNibSFu/mNw7PJKnyu5dAUcRbORecZ
fCHrH/YpfkHEZbjytMwnmazNhtfLn0TcAbWrSdX7yPrVNmJxfEQirNs+w2J/
eCLsdVZpvheRBWux8JX37SwIH7LOjYnAsF7xqYGaH4ZNFTtlt7rXwY2SV9tl
t9eBq4/Z0VzX71B44Y1OSVMjnCk6Hio2/xcsypjzyZjTCl+6d8ik2ndCZ1fT
wQrpDgjW4okUHOwGDal00Z3MLji3vDL69RMOCNzfr83gd0Pn8c4rSQUcOOdZ
NH+teA9YJok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cHLZ975EvO9koNcGD3T7Qj9nfS6xzD7FRd+XCtMVv+rHaRPjhcz6E/8aq
rLcn+6P2XS/u+rJRe22ulsPhfnz+vYxSqR8bFQzUf7hp0Y8/hF+tl73GRvIN
rHv5hv3Yc9G5HY9vsdHPa0XvMpb147rde3Qb49joqoS5vsQgB/sny7P0MRs1
FynuP3+Bg7uMbn2QllBE1rb9az6d7sP2JnbqC6cpois7fLSVjvXhn2ZrPbdI
K6Jxwe9QK7Jf/bK/TcNHThF1aYm5lxn34fJja7z72IrojxJauHFhH46/3LK4
dqEiMh9xsSn70YstCpffiDRSRA/rDo+tN+zFbxZVw5xbiqjx2FsNe/Ee7CSd
IqEhMxN5bpfdWWPbhQuTFui/CZ+JpF6tdCrR6MC1m/Qq9jKVUIBbccWbu22Y
7/Rgn12oEtIqtCh+H/kdV+5J3D9jpjKaaP3+Xj20Dttv0EtNjVJGcZ7WaWpx
Zdixv2b0R4wyKpG001SzLMOuD20NqPvKqLrn42klRhm+LHPtt2+8MmJN22Q/
fu01jmuqUt2booyCz79dpNhYir95W4WNFyqjhu6ZntHuxXhnsZu3eYsyqndO
mPErJRubu0hUBvxURhu/N7a0qWTjA/NiZpa0KaP51766N4c8xyeDX+Qu6lRG
x/ypQ1f/ZOLrh0S4/zjK6L2P5kCGbzouFd62T5lURh5PoxdFPn2IKzLnZreI
qCCe01lT9p0kXG2fPcUQV0EtYXnV6j0JuOXDl7iLUiros9H9+FG/WMyPVW3c
w1BBv7clFm9LD8dTZs8WBlAqyGHRzk2M3lA8TRzOv2SroNXD9tF3Lgdj9ml7
5iIVFVT39e/JC+lXsercEdvDqipoAdU2r+KyD57XcCMzTE0FvUjxsI9MP4eX
3VSaqJirgtbHnblclH4Ua296avJPQwUt1L79v/+3Sv8Ph2LZdw==
"]]},
Annotation[#, "Charting`Private`Tag$15294#1"]& ]}, {}},
AspectRatio->0.6180339887498948,
Axes->{True, True},
AxesLabel->{None, None},
AxesOrigin->{0, 0},
DisplayFunction->Identity,
Frame->{{False, False}, {False, False}},
FrameLabel->{{None, None}, {None, None}},
FrameTicks->{{Automatic, 
Charting`ScaledFrameTicks[{Identity, Identity}]}, {Automatic, 
Charting`ScaledFrameTicks[{Identity, Identity}]}},
GridLines->{None, None},
GridLinesStyle->Directive[
GrayLevel[0.5, 0.4]],
ImagePadding->All,
Method->{"DefaultBoundaryStyle" -> Automatic, "DefaultGraphicsInteraction" -> {"Version" -> 1.2, "TrackMousePosition" -> {True, False}, "Effects" -> {"Highlight" -> {"ratio" -> 2}, "HighlightPoint" -> {"ratio" -> 2}, "Droplines" -> {"freeformCursorMode" -> True, "placement" -> {"x" -> "All", "y" -> "None"}}}}, "DefaultMeshStyle" -> AbsolutePointSize[6], "ScalingFunctions" -> None, "CoordinatesToolOptions" -> {"DisplayFunction" -> ({
(
           Identity[#]& )[
Part[#, 1]], 
(Identity[#]& )[
Part[#, 2]]}& ), "CopiedValueFunction" -> ({
(Identity[#]& )[
Part[#, 1]], 
(Identity[#]& )[
Part[#, 2]]}& )}},
PlotRange->{{0, 6.283185307179586}, {-0.9999998592131705, 0.9999998782112116}},
PlotRangeClipping->True,
PlotRangePadding->{{
Scaled[0.02], 
Scaled[0.02]}, {
Scaled[0.05], 
Scaled[0.05]}},
Ticks->{Automatic, Automatic}]\), x^2, Entity["City", {"Enschede", "Overijssel", "Netherlands"}]}]
Out[4]=

Applications (3) 

Create a sorted deck of cards:

In[5]:=
deck = StringJoin@*Reverse /@ Tuples[{{"\[SpadeSuit]", "\[HeartSuit]", "\[DiamondSuit]", "\[ClubSuit]"}, Join[{"A"}, ToString /@ Range[2, 10], {"J", "Q", "K"}]}]
Out[5]=

Shuffle the deck once:

In[6]:=
ResourceFunction["OutShuffle"][deck]
Out[6]=

The original is obtained after only 8 out shuffles:

In[7]:=
ResourceFunction["OutShuffle"][deck, 8]
Out[7]=

Properties and Relations (3) 

An out shuffle does not change the first and last items for a list of even length:

In[8]:=
ResourceFunction["OutShuffle"][{1, 2, 3, 4, 5, 6}]
Out[8]=

An out shuffle does not change the first element:

In[9]:=
ResourceFunction["OutShuffle"][{1, 2, 3, 4, 5, 6, 7}]
Out[9]=

For a list of two, nothing happens:

In[10]:=
ResourceFunction["OutShuffle"][{1, 2}]
Out[10]=

Figure out after how many out shuffles a list of size L returns to its original order:

In[11]:=
howManyIterations[n_] := Length[NestWhileList[ResourceFunction["OutShuffle"], ResourceFunction["OutShuffle"]@Range[n], # =!= Range[n] &]]

For lists of even length, the number of shuffles to return to the original order is known analytically:

In[12]:=
howManyIterations[2 #] & /@ Range[10]
Out[12]=
In[13]:=
MultiplicativeOrder[2, 2 # - 1] & /@ Range[10]
Out[13]=

Visualize how the positions of items are changed for a list of length 22 in the form of a Graph:

In[14]:=
t = Range[22];
edges = Thread[t -> Ordering[ResourceFunction["OutShuffle"][t]]];
Graph[edges, VertexLabels -> "Name"]

Confirm that six nested out shuffles return the list of 22 items to the original order:

In[15]:=
t = Range[22];
edges = Thread[t -> Ordering[ResourceFunction["OutShuffle"][t, 6]]];
Graph[edges, VertexLabels -> "Name"]

Possible Issues (1) 

Zero iterations returns the original list:

In[16]:=
ResourceFunction["OutShuffle"][Range[10], 0]
Out[16]=

Neat Examples (1) 

Plot how many out shuffles are needed to return to the original order for a list of length L:

In[17]:=
howManyIterations[n_] := Length[NestWhileList[ResourceFunction["OutShuffle"], ResourceFunction["OutShuffle"]@Range[n], # =!= Range[n] &]]
data = Table[{i, howManyIterations[i]}, {i, 300}];
ListPlot[data, Frame -> True, FrameLabel -> {"L", "Number of shuffles needed"}, PlotRange -> All]
Out[19]=

Publisher

SHuisman

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 10 May 2019

Source Metadata

Related Resources

License Information