n = 10 truth = rmultinom(n,1,c(1/3,1/3,1/3)) # help(rnultinom) truth #help(rmultinom) truth = t(truth) truth truth = truth%*%seq(1,3,1) truth guess = 1 number_correct_NO_SWITCH = 0 number_correct_SWITCH = 0 for(i in 1:n) { #not swiching strategy wins if if(guess == truth[i])#otherwise guessing loses. { number_correct_NO_SWITCH = number_correct_NO_SWITCH + 1 } #swiching strategy wins if if(guess != truth[i])#otherwise switching loses { number_correct_SWITCH = number_correct_SWITCH + 1 } } number_correct_NO_SWITCH/n number_correct_SWITCH/n