Riffle shuffle a string - Robbers

7

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!

caird coinheringaahing

Posted 2018-01-01T02:46:55.363

Reputation: 13 702

Sandbox – caird coinheringaahing – 2018-01-01T02:52:04.207

Answers

1

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

fireflame241

Posted 2018-01-01T02:46:55.363

Reputation: 7 021

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! – HyperNeutrino – 2018-01-01T17:31:28.723

1

Jelly, HyperNeutrino

œs2UŒṖ€X€ż/

Try it online!

fireflame241

Posted 2018-01-01T02:46:55.363

Reputation: 7 021

0

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.

Mr. Xcoder

Posted 2018-01-01T02:46:55.363

Reputation: 39 774

0

R, Giuseppe

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

Try it online!

fergusq

Posted 2018-01-01T02:46:55.363

Reputation: 4 867

0

Pushy, FlipTack

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

Try It Online

Jo King

Posted 2018-01-01T02:46:55.363

Reputation: 38 234