0989卵の名無しさん
2021/04/24(土) 20:50:05.43ID:tLx5m1WD"
rm(list=ls())
sim <- function(n){
games=t(combn(n,2)) # combinations of match
nc=nrow(games) # number of combinations
winner=rbinom(nc,1,0.5)+1 # index of the winner 1 or 2
re=NULL # sequence of winners
for(i in 1:nc) re=c(re,games[i,winner[i]])
tbl=table(re)
sum(tbl==max(tbl))==1 # only one maximum?
}
f <- function(n,k=1e5) mean(replicate(k,sim(n)))
n=2:20
y=sapply(n,f)
plot(n,y,bty='l',pch=19,ylim=c(0,1),ylab='Prob')