# Function Repository Resource:

# OutShuffle

Perform an out shuffle on a list

Contributed by: Sander Huisman  |  SHuisman
 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:= Out= ### Scope (2)

Perform an out shuffle 3 times to a list:

 In:= Out= Confirm that this is the same:

 In:= Out= The list can contain expressions of different types:

 In:= Out= ### Applications (3)

Create a sorted deck of cards:

 In:= Out= Shuffle the deck once:

 In:= Out= The original is obtained after only 8 out shuffles:

 In:= Out= ### Properties and Relations (3)

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

 In:= Out= An out shuffle does not change the first element:

 In:= Out= For a list of two, nothing happens:

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

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

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

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

 In:=  ### Possible Issues (1)

Zero iterations returns the original list:

 In:= Out= ### Neat Examples (1)

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

 In:= Out= ## Requirements

Wolfram Language 11.3 (March 2018) or above