How could we calculate the final weight, knowing the initial and final water percentage, and initial weight‽?? I am doing the math exercise by hand before starting to write an answer for the following programming exercise: Drying potatoes. The statement is:

All we eat is water and dry matter.
John bought potatoes: their weight is 100 kilograms. Potatoes contain
  water and dry matter.
The water content is 99 percent of the total weight. He thinks they
  are too wet and puts them in an oven - at low temperature - for them
  to lose some water.
At the output the water content is only 98%.
What is the total weight in kilograms (water content plus dry matter)
  coming out of the oven?
He finds 50 kilograms and he thinks he made a mistake: "So much weight
  lost for such a small change in water content!"
Can you help him?
Write function potatoes with
int parameter p0 - initial percent of water-
int parameter w0 - initial weight -
int parameter p1 - final percent of water -

potatoesshould return the final weight coming out of the oven w1
  truncated as an int. Example:
potatoes(99, 100, 98) --> 50

I am trying to understand how can we solve by hand this exercise. I have tried the rule of 3:


*

*initial percentage of water -> initial weight

*final percentage of water -> x (final weight)


x = ( initial percentage of water - initial weight ) / final percentage of water;
x = 99 - 100 / 98 = -1 / 98 = -0,0102 (and it should be 50)...
Then I tried to use a linear equation as:
initial water percentage - final water percentage = initial weight - final weight (x); 99 - 98 = 100 - x; 99 - 98 - 100 = -x; x = 99 (and it should be 50)...
I have also observed the exercise's test cases where p0: initial water percentage, w0: initial weight, p1: final water percentage, w1: final weight (what we should be able to calculate)


*

*p0, w0, p1, w1

*82, 127, 80, 114

*93, 129, 91, 100


In addition I have also read:


*

*Solving linear equation

*What is a linear equation?

*Solve Linear Sytem of Equation for $u,v,w$

*https://www.purplemath.com/modules/systlin1.htm

*https://www.wtamu.edu/academic/anns/mps/math/mathlab/int_algebra/int_alg_tut7_lineq.htm
How could we calculate the final weight, knowing the initial water percentage, final water percentage, and initial weight‽??
 A: Define:
\begin{align*}
d &= \text{dry mass (both before and after)} \\
p_0 &= \text{initial water percentage} \\
p_1 &= \text{final water percentage} \\
w_0 &= \text{initial water mass} \\
w_0 &= \text{final water mass} \\
t_0 &= \text{initial total mass} \\
t_1 &= \text{final total mass}
\end{align*}
Then we have:
\begin{cases}
\dfrac{p_0}{100} = \dfrac{w_0}{w_0 + d} = \dfrac{w_0}{t_0} \\
\dfrac{p_1}{100} = \dfrac{w_1}{w_1 + d} = \dfrac{w_1}{t_1}
\end{cases}
Given $p_0, t_0, p_1$, we want to find $t_1$. To this end, observe that:
\begin{align*}
\dfrac{p_0}{100} = \dfrac{w_0}{t_0} &\implies \boxed{w_0 = t_0 \cdot \frac{p_0}{100}} \\
t_0 = d + w_0 &\implies \boxed{d = t_0 - w_0} \\
\dfrac{p_1}{100} = \dfrac{w_1}{w_1 + d} \implies p_1w_1 + p_1d = 100w_1 &\implies \boxed{w_1 = \frac{p_1d}{100 - p_1}}
\end{align*}
Putting it together, we find that:
$$
t_1 = d + w_1 = \left(1 + \frac{p_1}{100 - p_1} \right) \cdot t_0 \left(1 - \frac{p_0}{100} \right)
= t_0 \cdot \left( \frac{100 - p_0}{100 - p_1} \right)
$$
Indeed, for the first test case, we see that:
$$
t_1 = 100 \cdot \left( \frac{100 - 99}{100 - 98} \right) = 50
$$
