>>931
百万回のシミュレーション解

bag=rep(1:0,c(3,7))
sim <- function(){
ball=0
count=0
while(ball==0){
count=count+1
ball=sample(bag,1)
}
return(count)
}
re=replicate(1e6,sim())

> mean(re==4) # (1)
[1] 0.102998
> mean(re) # (2)
[1] 3.338686