Learn R Programming

permutations (version 1.1-6)

faro: Faro shuffles

Description

A faro shuffle, faro(),is a permutation of a deck of \(2n\) cards. The cards are split into two packs, 1:n and (n+1):2n, and interleaved: cards are taken alternately from top of each pack and placed face down on the table. A faro out-shuffle takes the first card from 1:n and a faro in-shuffle takes the first card from (n+1):(2*n).

A generalized faro shuffle, faro_gen(), splits the pack into m equal parts and applies the same permutation (p1) to each pack, and then permutes the packs with p2, before interleaving. The interleaving itself is simply a matrix transpose; it is possible to omit this step by passing interleave=FALSE.

Usage

faro(n, out = TRUE)
faro_gen(n,m,p1=id,p2=id,interleave=TRUE)

Value

Returns a permutation in word form

Arguments

n

Number of cards in each pack

m

Number of packs

p1,p2

Permutations for cards and packs respectively, coerced to word form

interleave

Boolean, with default TRUE meaning to actually perform the interleaving and FALSE meaning not to

out

Boolean, with default TRUE meaning to return an out-shuffle and FALSE meaning to return an in-shuffle

Author

Robin K. S. Hankin

Examples

Run this code
faro(4)
faro(4,FALSE)

## Do a perfect riffle shuffle 52 times, return pack to original order:
permorder(faro(26))

## 15 cards, split into 5 packs of 3, cyclically permute each pack:
faro_gen(3, 5, p1=cyc_len(3), interleave=FALSE)

## 15 cards, split into 5 packs of 3, permute the packs as (13542):
print_word(faro_gen(3, 5, p2=as.cycle("(13542)"), interleave=FALSE))


sapply(seq_len(10),function(n){permorder(faro(n,FALSE))}) # OEIS  A002326

plot(as.vector(as.word(faro(10))),type='b')
plot(as.vector(faro_gen(8,5,p1=cyc_len(8)^2,interleave=FALSE)))


Run the code above in your browser using DataLab