Wow! Some great responses! I am getting some great responses. I've only read David, Michael, and Dennis thus far, leading me to develop this result before reading further.
lead <- function(x) { n <- length(x) count <- 0 if (x[1] >= 0) count <- count + 1 for (i in 2:n) { if (x[i] > 0 || (x[i] == 0 && x[i-1] >= 0 )) { count <- count + 1 } } count } games <- replicate(10000,sample(c(-1,1),40,replace=TRUE)) games_sum <- apply(games,2,sum) plot(table(games_sum)) games_lead <- apply(games,2,cumsum) games_lead <- apply(games_lead,2,lead) plot(table(games_lead)) Now I am going to read Arun, William, and Jeff's responses and see what other ideas are being proposed. Thanks everyone. D. -- View this message in context: http://r.789695.n4.nabble.com/Head-or-Tails-game-tp4639142p4639150.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.