# Riffle shuffle a string - Robbers

Cops post

A riffle shuffle is a way of shuffling cards where the deck is split into 2 roughly equal sections and the sections are riffled into each other in small groups. This is how to riffle shuffle a string:

• Split the string into equal sections.
• Reverse the string, and starting from the start of each string.
• Put runs of a random length between 1 and the number of characters left into the final string
• Then remove these characters from the strings.

An example

"Hello World!"      Output string = ""
"Hello ", "World!"  ""
"Hell", "World!"    " o"
"Hell", "World"     " o!"
"Hel", "World"      " o!l"
"Hel", "Wo"         " o!ldlr"
"H", "Wo"           " o!ldlrle"
"H", ""             " o!ldlrleoW"
"", ""              " o!ldlrleoWH"


The final product from Hello World! could be o!ldlrleoWH and that is what you would output.

## Robbers

Your task is to take a Cops submission and rearrange so that it produces a valid riffle shuffler program. You may not add, remove or change any characters in the original program to result in your solution.

If the program works, even if it is not the cops intended solution, it is a valid crack.

The winner is the person who cracks the most Cops submissions!

• Sandbox Jan 1, 2018 at 2:52

# Python 3, HyperNeutrino

from random import*
def r(i):
s=len(i)//2;L,R=i[:s][::-1],i[s:][::-1];o=[]
while L and R:s=randint(1,len(L));o+=L[:s];L,R=R,L[s:]
return o+L+R


Try it online!

Proof of Same Character Set

• Sorry, my original post had a slight issue. The new version shouldn't be too hard to determine from your current progress. Good job though, this was my original solution! Jan 1, 2018 at 17:31

# Jelly, HyperNeutrino

œs2UŒṖ€X€ż/


Try it online!

# Pyth, notjagan

jk.iFmO./_dc2Q


Try it here!

### Explanation

The Pyth interpreter also offers a nice pseudo-code if you check the "Debug" box.

• c2Q chops the input into 2 pieces of equal length, with initial pieces one longer if necessary.

• m maps a function over the pieces. Variable: d.

• _d reverses d
• ./ partitions the reverse of d; returns all divisions of the reversed d into disjoint contiguous substrings.
• O chooses a randOm partition.
• .iF Folds (reduces) the list by .interleaving.
• And finally jk joins the list of strings.

# R, Giuseppe

function(s){n<-nchar(s)
s<-methods::el(strsplit(s,''))
r<-tail(s,n/2)
o<-{}
while(length(l)|length(r)){if(length(r)){y<-sample(length(r),1)
r<-tail(r,-y)}
if(length(l)){x<-sample(length(l),1)
l<-tail(l,-x)}}
cat(o,sep='')}


Try it online!

# Pushy, FlipTack

L2/:v;O@N[1LU:'.;FL0=?x?i


Try It Online