4 min read

On camels and straws

Table of Contents

Puzzle

A camel is loaded with straws until its back breaks. Each straw gas a weight uniformly distributed 00 and 11, independent of the other straws. The camel’s back breaks as soon as the total weight of all the straws exceeds 11.

Problem 1

Find the expected number of straws that break the camel’s back.

Solution (using integral equation)

Let XiX_i be the random variable representing the weight of each straw and let f(t)f(t) be the expected number of straws that need to be drawn such that βˆ‘Xiβ‰₯t\sum X_i \geq t for t∈[0,1]t \in [0,1].

We have the following integral equation:

f(t)=1+∫0tf(tβˆ’x)dxf(t) = 1 + \int_0^t f(t-x)dx

Differentiating on both sides, we get the differential equation fβ€²(t)=f(t)f'(t) = f(t) with the boundary condition f(0)=1f(0)=1.

The solution to the above differential equation is f(t)=etf(t)=e^t and the expected number of straws is f(1)=ef(1)=\textbf{e}.

Solution (using Irwin-Hall Distribution)

Let Sn=βˆ‘i=1nXnS_n = \sum_{i=1}^n X_n be the random variable representing the sum of nn uniform random variables (i.e. sum of the weights of nn straws in this case). SnS_n follows the Irwin-Hall distribution. For x∈[0,1]x \in [0,1], the PDF of SnS_n is given by xn/n!x^n/n!.

Let NN be the random variable for the number of straws required such that βˆ‘i=1NXiβ‰₯1\sum_{i=1}^N X_i \geq 1. We see that

P[N=n]=P[Snβˆ’1<1Β andΒ Sn>1]=P[1βˆ’Xn<Snβˆ’1<1]=∫011(nβˆ’1)!βˆ’(1βˆ’x)nβˆ’1(nβˆ’1)!dx=nβˆ’1n!\begin{aligned} \mathbb{P}[N=n] &= \mathbb{P}[S_{n-1} < 1 \text{ and } S_{n} > 1] \\\\ &= \mathbb{P}[1 - X_{n} < S_{n-1} < 1] \\\\ & = \int_0^1 \frac{1}{(n-1)!} - \frac{(1-x)^{n-1}}{(n-1)!} dx \\\\ & = \frac{n-1}{n!} \end{aligned}

The expected number of straws satisfying the condition is given by

E[N]=βˆ‘n=2∞nβ‹…P[N=n]=βˆ‘n=2∞1(nβˆ’2)!=e.\mathbb{E}[N] = \sum_{n=2}^\infty n\cdot\mathbb{P}[N=n] = \sum_{n=2}^\infty \frac{1}{(n-2)!} = \textbf{e}.

Computational verification

From the simulation below, we see that the expected weight of the last straw is β‰ˆ2.718\approx \textbf{2.718}.

from random import random
runs, sum_num_straws = 1000000, 0
for _ in range(runs):
    num_straws, weight = 0,0
    while (weight < 1):
        weight += random()
    sum_num_straws += num_straws
print(sum_num_straws/runs)

Problem 2

Find the probability that the weight of the last straw is less than or equal to xx.

Solution (using Irwin-Hall distribution)

Let XX be the random variable representing the weight of the last straw. We have the conditional distribution

P[X≀xΒ andΒ N=n]=P[X≀xΒ andΒ Snβˆ’1<1Β andΒ Sn>1]=P[X≀xΒ andΒ 1βˆ’Xn<Snβˆ’1<1]=∫0x1(nβˆ’1)!βˆ’(1βˆ’x)nβˆ’1(nβˆ’1)!dx=(1βˆ’x)nβˆ’1+nxn!\begin{aligned} \mathbb{P}[X \leq x \text{ and } N = n] &= \mathbb{P}[X \leq x \text{ and } S_{n-1} < 1 \text{ and } S_{n} > 1] \\\\ &= \mathbb{P}[X \leq x \text{ and } 1 - X_{n} < S_{n-1} < 1] \\\\ &= \int_0^x \frac{1}{(n-1)!} - \frac{(1-x)^{n-1}}{(n-1)!} dx \\\\ &= \frac{(1-x)^n - 1 + nx}{n!} \end{aligned}

Therefore the required probability distribution for XX is

P[X≀x]=βˆ‘n=2∞P[X≀xΒ andΒ N=n]=e1βˆ’xβˆ’e+ex\begin{aligned} \mathbb{P}[X \leq x] &= \sum_{n=2}^\infty \mathbb{P}[X \leq x \text { and } N=n] \\\\ &= e^{1-x} - e + ex \end{aligned}

Problem 3

Find the expected weight of the last straw that breaks the camel’s back.

Solution (using Irwin-Hall distribution)

From the probability distribution calculated above, we get the probability density function of XX which is eβˆ’e1βˆ’xe - e^{1-x}.

Therefore, the expected weight of the last straw is given by

E[X]=∫01x(eβˆ’e1βˆ’x)dx=2βˆ’e2.\mathbb{E}[X] = \int_0^1 x(e - e^{1-x}) dx = 2 - \frac{e}{2}.

Solution (using integral equation)

Let XiX_i be the random variable representing the weight of each straw and let w(t)w(t) be the expected weight of the last straw that needs to be drawn such that βˆ‘Xiβ‰₯t\sum X_i \geq t for t∈[0,1]t \in [0,1]. We have the following integral equation:

w(t)=∫t1xdx+∫0tw(tβˆ’x)dxw(t) = \int_{t}^{1} x dx + \int_{0}^t w(t-x) dx

Differentiating both sides, we get the differential equation wβ€²(t)=βˆ’t+w(t)w'(t) = -t + w(t) with the boundary condition w(0)=12w(0) = \frac{1}{2}.

The solution to the above differential equation is w(t)=βˆ’12et+t+1w(t)=-\frac{1}{2}e^t + t + 1 and the expected weight of the last straw is w(1)=2βˆ’e2w(1)=2-\frac{e}{2}.

Computational verification

From the simulation below, we see that the expected weight of the last straw is β‰ˆ0.64\approx \textbf{0.64}.

from random import random
runs, sum_last_straw_weight = 1000000, 0
for _ in range(runs):
    weight = 0
    while (weight < 1):
        straw = random()
        weight += straw
    sum_last_straw_weight += straw
print(sum_last_straw_weight/runs)