I need to do a Monte Carlo simulation in R for this problem:
Three tourists arrive in a town that has five hotels. What is the probability that the three tourists each sign into a different hotel? And what is the probability they all sign in at the same hotel? The hotels have the same characteristics.
I'm lost with it, I tried with the code below, but didn't seem to work.
esperanza_Xn <- function(n,p,m) {
sim=0; q=1-p
for(i in 1:m){
r=runif(n,1,p)
e=2*r-1; X=0
for(j in 1:n){
X[j+1]=X[j]+e[j]
}
sim[i]=X[n+1]}
a=paste("E(X_n) teórico=",n*(p-q))
b=paste("E(X_n) Monte Carlo=",mean(sim))
rbind(a,b)
}
EXAMPLE
esperanza_Xn(100,5,3)