The Cake Cutting Problem
Introduction
Alon Amit’s post gave a very good explanation about the cake cutting problem. In mathematical language, the problem is stated as:
What is the probability that
The answer is the Golomb-Dickman constant
I wrote the following R program:
simu_exp_1 <- function()
{x <- 1
first_cut <- runif(1, min = 0, max = x)
temp <- first_cut
while(1) {
x <- x - temp
if(x < first_cut) return(1)
next_cut <- runif(1, min = 0, max = x)
if(next_cut > first_cut) return(0)
temp <- next_cut
}
}
N <- 1000000
simu_re <- replicate(n = N, simu_exp_1())
mean_re <- cumsum(simu_re) / (1:N)
(mean_re[N])
## [1] 0.623832
Inspired by the above cake cutting problem, I asked myself the following question:
Define
When
Finding
In the case
Thus,
Finding by simulation
My R code is given below
simu_exp_2 <- function(n = 2)
{x <- rep(0, n)
x[1] <- runif(1, min = 0, max = 1)
for(i in 2:n) {
x[i] <- runif(1, min = 0, max = 1 - sum(x[1:(i-1)]))
}
y <- sort(x, decreasing = TRUE)
if(identical(x, y)) return(1)
return(0)
}
get_result <- function(n = 2)
{N <- 1000000
simu_re <- replicate(n = N, simu_exp_2(n))
mean_re <- cumsum(simu_re) / (1:N)
mean_re[N]
}
(get_result(n = 2))
## [1] 0.692733
(get_result(n = 3))
## [1] 0.431809
(get_result(n = 4))
## [1] 0.260376