A friend of mine - well more of a colleague really, let’s call him Steve, uses the following system to decide who pays the bill when he goes out to dinner with his girlfriend: they roll a dice, and if the outcome is a 1, 2, 3 or 4, he pays. Otherwise she pays.
So far so good. But his girlfriend thought that he was paing too often (yes, he’s found a good one), so he came up with the following additional rule: noone should pay more than twice in a row. Meaning that if he has payed the last 2 times, the next time they go out, she will automatically pay, no need to roll the dice. Same for her.
Now the question is: what is the proportion of the time that he will be paying ? Intuitively, we can tell it will be closer to 0.5, but how much closer ?
roll_dice = function(roll1, roll2){
if(roll1 == 1 && roll2 == 1){
0
}
else if(roll1 == 0 && roll2 ==0){
1
}
else{
r = floor(runif(1, 1, 7))
(r <= 4)
}
}
simul = function(n){
roll1 = -1
roll2 = -1
rolls = NULL
for(i in 1:n){
r = roll_dice(roll1, roll2)
roll2 = roll1
roll1 = r
rolls = c(rolls, r)
}
rolls
}
Here’s the plot of the proportion of the time that Steven pays as a function of the number of times they went out:
n = 100000
s = cumsum(simul(n))
x = 1:n
y = mapply(function(x, y) x/y, s, 1:n)
plot(x, y, type="l", xlab="Number of dates", ylab="% of the time Steven pays", ylim=c(0.55,0.56), col="red")
And the final answer is:
y[length(y)]
## [1] 0.55615