R/faro.R

Defines functions `faro_gen` `faro`

`faro` <- function(n,out=TRUE){
  if(out){
    return(faro_gen(n,2,p2=cyc_len(2)))
  } else {
    return(faro_gen(n,2))
  }
}

`faro_gen` <- function(n,m,p1=id,p2=id,interleave=TRUE){# generalized Faro shuffle
  M <- matrix(seq_len(n*m),n,m)
  p1 <- as.word(p1)
  p2 <- as.word(p2)
  size(p1) <- n
  size(p2) <- m
  M <- M[as.function(p1)(seq_len(n)),as.function(p2)(seq_len(m))]
  if(interleave){M <- t(M)}
  as.word(c(M))
}

Try the permutations package in your browser

Any scripts or data that you put into this service are public.

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