faro: Faro shuffles

faroR Documentation

Faro shuffles

Description

\loadmathjax

A faro shuffle, faro(),is a permutation of a deck of \mjseqn2n 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 to each pack, and the same permutation to each set of packs, 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)

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

Value

Returns a permutation in word form

Author(s)

Robin K. S. Hankin

Examples

faro(4)
faro(4,FALSE)

faro_gen(9,3)
faro_gen(7,4,cyc_len(7),cyc_len(4))
faro_gen(7,4,cyc_len(7),cyc_len(4),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)))


permutations documentation built on March 7, 2023, 8:26 p.m.