Faro shuffles
faro.Rd
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 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
.
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 andFALSE
meaning not to- out
Boolean, with default
TRUE
meaning to return an out-shuffle andFALSE
meaning to return an in-shuffle
Examples
faro(4)
#> [1] (157842)(36)
#> [coerced from word form]
faro(4,FALSE)
#> [1] (253)(467)
#> [coerced from word form]
faro_gen(9,3)
#> [1] (2,10,4)(3,19,7)(5,11,13)(6,20,16)(8,12,22)(9,21,25)(15,23,17)(18,24,26)
#> [coerced from word form]
faro_gen(7,4,cyc_len(7),cyc_len(4))
#> [1] (1,9,11,25,8,3,23,28)(2,16,5,10,18,20,6,17,13,12,4)(7,24)(14,19,27,22,21)(15,26)
#> [coerced from word form]
faro_gen(7,4,cyc_len(7),cyc_len(4),interleave=FALSE)
#> [1] (1,9,17,25,5,13,21,22,2,10,18,26,6,14,15,23,3,11,19,27,7,8,16,24,4,12,20,28)
#> [coerced from word form]
sapply(seq_len(10),function(n){permorder(faro(n,FALSE))}) # OEIS A002326
#> [1] 1 2 4 3 6 10 12 4 8 18
plot(as.vector(as.word(faro(10))),type='b')
plot(as.vector(faro_gen(8,5,p1=cyc_len(8)^2,interleave=FALSE)))