We are playing a game. I will generate a random number from Uniform(0,1), then you will guess whether or not the next number will be higher or lower than the current number. Every time you guess correctly you get a point. The game ends when you guess incorrectly. What is the expected amount of points you will get?
I have simulated this in Python and get $2.695 \approx e$. However, I am struggling to formulate an analytical solution by working backwards : $e = \sum_{i=0}^\infty i \cdot f(i) $ where $f(n)$ is the probability of the $n$ being the length. Thank you
Here is my approach.
Let $X_1,X_2,...\sim \mathcal{U}(0,1)$ be iid. Take $N$ as the number of times you win the game. Clearly, if you're shown a number between $0$ and $0.5$ you'll guess "higher," and if the number is between $0.5$ and $1$ you'll guess "lower."
For $x\in (0,1)$ define the function $f$ by $f(x)=\mathbb{E}(N|X_1=x)$.
First of all, if $x$ belongs to $(0,0.5)$ then $$f(x)=\int_{x}^1\mathbb{E}(N|X_1=x,X_2=y)f_{X_2}(y)\mathrm{d}y$$
From recursion $\mathbb{E}(N|X_1=x,X_2=y)=1+f(y)$ whenever $x<y<1$. This means we can say $$f(x)=\int_{x}^1\big(1+f(y)\big)\mathrm{d}y=1-x+\int_x^1f(t)\mathrm{d}t$$ Using a similar recursion style logic, you can also say for $0.5<x<1$ that $$f(x)=x+\int_0^xf(t)\mathrm{d}t$$ If you solve these integral equations, you'll get general solutions of the form $$f(x)=Ae^{-x}-1 \text{ whenever } 0<x<0.5$$ $$f(x)=Be^x-1 \text{ whenever }0.5<x<1$$ Clearly we seek to have these expression agree at $x=0.5$. It is also crucial that we have $$\lim_{x\mapsto 0^{+}}f(x)=1+\mathbb{E}(N)=1+\int_0^1f(x)\mathrm{d}x$$ Imposing both of these conditions yields the following formula for $f(x)$: $$f(x)=\frac{e^{1-x}}{2\sqrt{e}-e}-1 \text{ whenever } 0<x\leq 0.5$$ $$f(x)=\frac{e^{x}}{2\sqrt{e}-e}-1 \text{ whenever } 0.5 \leq x<1 $$ Finally, $$\mathbb{E}(N)=\int_0^1 f(x)\mathrm{d}x = \frac{2}{2-\sqrt{e}}-3 \approx 2.69$$ which agrees with your simulation!