How to solve equation with the floor function? 100 sided die Problem The 100 sided die problem has been asked before:
100-sided die probability.
You are given a 100-sided die. After you roll once, you can choose to either get paid the dollar amount of that roll OR pay one dollar for one more roll. What is the expected value of the game? There is no limit on number of rolls.
The solution amounts to solving the equation, where the floor function is necessary because of the discrete die:
(1)$E=\dfrac {\lfloor E-1\rfloor }{100}\cdot \left( E-1\right) + \left( 1-\dfrac {\lfloor E-1\rfloor }{100}\right)\cdot\dfrac {\lfloor E\rfloor +100}{2} $          
eg. Say the expected value is 87.5, you would roll again if you got x≤86 as your expected value is 86.5 after one roll  (E-1), so with probability 86/100 your expected value would be E-1, if you got 87 or above, then obviously your expected value is $\dfrac {(100+87)}{2}$
The solution is $\dfrac {1223}{14}$
Now how do you solve that equation, without a numerical approach ?
I know that setting $\lfloor E\rfloor $= B and then writing the equation in terms of E, finding the roots ie when E is maximised, somehow works.
ie. $E = \dfrac {(B^2 + B - 10102)}{(2 (B - 101)} $ 
Then find the B that maximises this equation, which is $B = 101 - 10\sqrt {2}$, then try the nearest integer values, $\lceil B\rceil $, $\lfloor B\rfloor $ and see which one maximises the equation.
Does anybody know why that works and is that the best way to solve the equation, as this is an interview question after all?
 A: The reason your substitution works is that the equation is a nice smooth quadratic.  If the maximum is between two integer inputs, the highest value with an integer input will be on one side of the maximum or the other.  If the degree is higher it usually still works, though you can find cases where it doesn't.  
This is a fine approach for solving it.
A: Let $E$ be the solution of the above equation $(1)$.
Let $B=\lfloor E\rfloor$, so $B\le E<B+1$, then we use 
$\lfloor E-1\rfloor=B-1$ to rewrite $(1)$ as 
$$
(2)\qquad
E
\underbrace{\left(1-\frac{B-1}{100}\right)}_{>0}
= 
-\frac {B-1}{100} 
+ 
\left( 1-\frac {B-1}{100}\right)
\cdot
\frac {B +100}{2}
\ .
$$
(The positive term is so, since we cannot win more than $100$ in the game.)
This implies the double inequality restricting $B$,
$$
(3)\qquad
B\cdot
\frac{101-B}{100}
\ \overset{(L)}\le\
-\frac {B-1}{100} 
+ 
\frac {101-B}{100}
\cdot
\frac {B +100}{2}
\ \overset{(R)}<\ 
(B+1)\cdot
\frac{101-B}{100}\ .
$$
To find a "good" $B$, we consider the corresponding functions of second degree, then their roots.


*

*For the left inequality (L), we have equality for the values
$$
B^L_{1,2}=\frac 12(203\pm 2\sqrt{89})
\ ,\qquad B_1^L<B_2^L\ ,
$$
and the inequality prescribes $B\not\in[B_1^L,B_2^L]$, and this excluded interval is numerically 
$[\ \color{red}{87.34}90283019150, \ 115.650971698085\ ]$,

*for the right inequality (R), we have equality for the values
$$
B^R_{1,2}=\frac 12(201\pm 2\sqrt{89})
\ ,\qquad B_1^L<B_2^L\ ,
$$
and the inequality prescribes $B\in[B_1^R,B_2^R]$,
and this interval is numerically
$[\ \color{red}{86.34}90283019152, \ 114.650971698085\ ]$.
The only matching $B\in\Bbb N$ is
$$ B= 87\ .$$
(So it "must be" the value, the backwards implication.)
Using (1), or (2), or $E=g(B)=(B^2+B-10102)/(2(B-1))$, we get the promised value for $E$, $E=g(87)=1223/14$.
Comment: The above is a low level way to proceed. The posted maximality for the function relating $E$ and $B$, 
$E=g(B)$,
is not involved. But there may be a speculative connection, as seen above in $(L)$, we take $B$ to be the maximal solution of (L), equivalently written $B=g(B)$. (Since this maximal solution is the only one that respects also (R). This explains why we take the integer $B$ making $g$ maximal.)
