一个均匀硬币不断抛啊抛,一直抛到出现HTT(正反反)和HTH(正反正),哪个需要抛的次数多?
感觉次数应该是一样的,从理论上来说。
有人写了代码:
<br />
coin.seq = function(v) {<br />
x = NULL<br />
n = 0<br />
while (!identical(x, v)) {<br />
x = append(x[length(x) - 1:0], rbinom(1, 1, 0.5))<br />
n = n + 1<br />
}<br />
n<br />
}<br />
set.seed(1024)<br />
mean(htt <- replicate(1e+05, coin.seq(c(1, 0, 0))))<br />
# [1] 8.003<br />
mean(hth <- replicate(1e+05, coin.seq(c(1, 0, 1))))<br />
# [1] 10.006<br />
我觉得不对,请各位看看。
</p>