Reputation: 286
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, but accounting for repetitions?. 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%). Also we cant use Ifs/whiles
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() ))
Upvotes: 0
Views: 37
Reputation: 286
I think I got it:
game <- function(){
a <- sort(sample(1:6,3, replace = T))
#print(a)
b <- sort(sample(1:6,3, replace = T))
#print(b)
identical(a,b)
}
mean(replicate(10000, game() ))
Upvotes: 3