Advertisement
Guest User

Untitled

a guest
Aug 30th, 2017
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.40 KB | None | 0 0
  1. z <- c()
  2.  
  3. for(j in 1:10000) {
  4. x <- c()
  5.   y <- c()
  6.  
  7.   for(i in 1:100) {
  8.  
  9.     y <- c(y, rbinom(1, 1, .5))
  10.  
  11.     if (i > 3) {
  12.  
  13.       if (y[i-1] == 1 & y[i-2] == 1 & y[i-3] == 1) {
  14.  
  15.         if (y[i] == 1) {
  16.  
  17.           x <- c(x,1)
  18.  
  19.         } else {
  20.  
  21.           x <- c(x,0)
  22.        
  23.         }
  24.  
  25.       }
  26.  
  27.     }
  28.    
  29.   }
  30.    
  31.    if (length(x) > 0) {
  32.    z <- c(z, sample(x,1))
  33.    }
  34. }
  35.  
  36. mean(z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement