20/03/16 08:51:01.03 CVVw1pKV.net
>>814
総当たりで計算
# A,A,A,B,B,C,D,E,F,Gの10文字を並べるとき、どこかで同じ文字が隣り合う確率を求めよ(東北大・改)
library(gtools)
v=rep(1:7,c(3,2,rep(1,5)))
pm=try(permutations(10,10,v,set=F))
tail(pm)
f <- function(x){
n=length(x)
flg=FALSE
for(i in 1:(n-1)){
if(x[i]==x[i+1]){
flg=TRUE
break
}
}
return(flg)
}
(x=pm[10000,])
re=sum(apply(pm,1,f))
library(gmp)
N=nrow(pm)
as.bigq(re/N)
re/N
Big Rational ('bigq') :
[1] 1388609885105903/2251799813685248
> re/N
[1] 0.6166667