#Two functions that can be used to simulate the following game: #(1) we place 4 coins on a table, (2) we choose a number k at random #from the set 1:5, (3) if we choose k=5 we do nothing, but otherwise #we turn over coin k. We then repeat this process 10 times. chooseandturn<-function(v){ k<-sample(1:5,1,F,c(1/5,1/5,1/5,1/5,1/5)); if(k<5){v[k]<-(-1)*v[k]}; return(v) } getNafter10<-function(){ v<-c(1,1,1,1); for(j in 1:10){v<-chooseandturn(v)}; return(2+sum(v)/2) } #We can then use this code to find the distribution of N, #the number of heads that one has from the 10-step process.