The Broken Calculator Problem

561 Views Asked by At

So here is the Problem :-

Tom has a specific calculator . Unfortunately, all keys are broken except for one row$: 1,2,3,+,-$. Tom presses a sequence of $5$ random keys; where at each stroke, each key is equally likely to be pressed. The calculator then evaluates the entire expression, yielding a result of E. Find the Expected Value of E.

Before doing this we need to remember some facts :-

$(i)$ Excess Operators will be parsed as signs. For e.g. :- $-2-+3$ gives $E = -5$.and $-+-31$ gives $E = 31$

$(ii)$ Trailing Operators are discarded . For e.g. :- $2-+--$ gives $E = 2$

$(iii)$ Negative Sums are allowed . For e.g. :- $13 - 22$ give $E = -9$.

$(iv)$ A string consisting only of operators , gives $E$ as $0$ .

This Problem looks very interesting to me . First of all there can be many different types of sums for E and second, it's definitely not quite easy to get the expected value of it, and I don't know who to start doing it . Any ideas for this problem will be greatly appreciated !!

1

There are 1 best solutions below

4
On BEST ANSWER

Any string that starts with an operator is cancelled out by switching every operator in front of a number (if an operator is in front another operator, then leave it untouched). For example, if you have $−1234$, it is cancelled out by $+1234$. If you have $++123$, it is cancelled out by $+−123$. If you have $−1++3$, it is cancelled out by $+1+−3$. Therefore, we have to calculate the sum of all the results obtained from strings starting with a number.

Now, let $d$ be a number string of length at most $5$ with digits in $\{1,2,3\}$. Let $s(d)$ denote the sum of all values corresponding to strings of length $5$ starting with $d$ and the entry next to the end of $d$ is a sign (or if $d$ has length $5$ already, it is not followed by any sign). Show that $$s(d)=\left\{\begin{array}{ll} \text{value}(d)\cdot\left(2\cdot 5^{4-\text{length}(d)}\right)&\text{if }\text{length}(d)<5\,,\\ \text{value}(d)\cdot 1&\text{if }\text{length}(d)=5 \,,\end{array}\right.$$ where $\text{length}(d)$ is the length of $d$, and $\text{value}(d)$ is the value of the string $d$ when interpreted as an integer.

If $S$ is the sum of all $s(d)$ where $d$ runs over all the number strings of length at most $5$ with digits in $\{1,2,3\}$, then show that $$\begin{align}S&=3^0\cdot 6\cdot (2\cdot 5^3)+3^1\cdot 66\cdot (2\cdot 5^2)+3^2\cdot 666\cdot (2\cdot 5)\\&\phantom{abcde}+3^3\cdot 6666\cdot 2+3^4\cdot 66666\cdot 1=5831250\,.\end{align}$$ The expected value is then $$\dfrac{S}{5^5}=\frac{5831250}{3125}=1866\,.$$

If the calculator calculates the results in base $b$, and there are $k$ available digits $t_1,t_2,\ldots,t_k$ (the available signs are still $+$ and $-$), then the expected value of the results from pressing the calculator $n$ times is $$\frac{\sum\limits_{j=1}^k\,t_j}{(k+2)^n}\,\left(\sum_{r=1}^{n-1}\,k^{r-1}\,\frac{b^r-1}{b-1}\,\left(2\cdot (k+2)^{n-1-r}\right)+k^{n-1}\,\frac{b^n-1}{b-1}\right)\,.$$ I am leaving a proof and the simplification of the long expression above for the curious reader.