23/01/24 03:17:41.05 boI46Rt9H.net
> f=\(n){
+ s=sum(sample(0:1,n,replace=TRUE))
+ ifelse(s==0||s==n,n,min(s,n-s))
+ }
> sim =\(n){
+ flg <- f(n)==1||f(n)==2
+ i=1
+ while(!flg){
+ i=i+1
+ n=f(n)
+ flg <- f(n)==1||f(n)==2
+ }
+ i
+ }
> mean(replicate(1e6,sim(7)))
[1] 1.748976