For example a two player board game allows the players to roll 3 dice, what is the probability that they roll the same values, ignoring the order. Such as (8,2,2) is the same as (2,8,2). I'm not sure that we can use identical() and I attempted the use of any() too, but I am not getting the answer I need. (which is around 2.1% or 2.2%).
game <- function(){ a <- sample(1:6,3, replace = T) #print(a) b <- sample(1:6,3, replace = T) #print(b) identical(any(a[a]),any(b[b])) } mean(replicate(10000, game() )) https://stackoverflow.com/questions/66539388/r-programming-how-do-i-account-for-repetitions-when-order-doesnt-matter-when-c March 09, 2021 at 09:08AM
没有评论:
发表评论