Skip to content

Instantly share code, notes, and snippets.

@certifiedwaif
Created February 16, 2016 05:10
Show Gist options
  • Save certifiedwaif/d322b13d410b520395df to your computer and use it in GitHub Desktop.
Save certifiedwaif/d322b13d410b520395df to your computer and use it in GitHub Desktop.
I think the intent of this code is perfectly obvious</sarcasm>
greycode <- function(p)
{
A <- matrix(c(0,1),2,1)
if (p!=1) {
for (i in 2:p) {
P <- nrow(A)
inds <- rev(1:P)
A1 <- matrix(c(rep(0,P),rep(1,P)),2*P,1)
A2 <- rbind(A,matrix(A[inds,],nrow(A),ncol(A)))
A <- cbind(A1,A2)
}
}
return(A)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment