TITLE: What would be the mathematical solution to this question?
QUESTION [6 upvotes]: I know that usually, your not supposed to ask homework questions, but I figure it's ok now, as I've already kind of solved it.
Three clever monkeys divide a pile of bananas. The first monkey takes some bananas from the pile, keeps three-fourths of them, and divides the rest equally between the other two. The second monkey takes some bananas from the pile, keeps one-fourth of them, and divides the rest equally between the other two. The third monkey takes the remaining bananas from the pile, keeps one-twelfth of them, and divides the rest equally between the other two. Given that each monkey receives a whole number of bananas whenever the bananas are divided, and the numbers of bananas the first, second, and third monkeys have at the end of the process are in the ratio $3:2:1$, what is the least possible total for the number of bananas?
After some pretty unhealthy Python bashing, I came up with a program that told me the answer, 408. But, that was a math question, so I'm curious to know: how would I solve it if I didn't use Python.

REPLY [3 votes]: Let $n$ be the total number of bananas. Let $x$, $y$ and $z$ be the number of bananas taken from the pile by the first, second and third monkey respectively. Since by the end all bananas have been taken, we have $x+y+z=n$.
The first monkey takes $x$ bananas and keeps $\frac34x$, whilst the other two monkeys get $\frac18x$ each. Similarly the second monkey takes $y$ bananas, keeping $\frac14y$, whilst the other two get $\frac38y$ each. And the third monkey takes $z$ bananas, keeping $\frac1{12}z$, whilst the others get $\frac{11}{24}z$ each.
Now suppose that the third monkey ends up with $k$ bananas. We have $\frac18x+\frac38y+\frac{1}{12}z=k$. Because of the ratio $3:2:1$, the first and second monkey have $3k$ and $2k$ bananas respectively. We can set up similar equations for these two monkeys, namely $\frac34x+\frac38y+\frac{11}{24}z=3k$ and $\frac18x+\frac14y+\frac{11}{24}z=2k$. Now you can solve the following system for $x$, $y$ and $z$:
\begin{align*}
\begin{pmatrix}
\frac34 & \frac38 & \frac{11}{24}\\
\frac18 & \frac14 & \frac{11}{24}\\
\frac18 & \frac38 & \frac{1}{12}
\end{pmatrix}
\begin{pmatrix}
x\\y\\z
\end{pmatrix}
=
\begin{pmatrix}
3k\\2k\\k
\end{pmatrix}
\end{align*}
This gives $x=\frac{22}{17}k$, $y=\frac{26}{17}k$ and $z=\frac{54}{17}k$. I'll just set $p=\frac{k}{17}$ to make this nicer. So $x=22p$, $y=26p$ and $z=54p$. We just need to find $p$ now.
Each fraction in our system of equations represents a whole number of bananas being distributed. So we need to make sure that all the fractions in our system are whole numbers. In other words, you are looking for the smallest positive number $p$ such that $\frac14\cdot22p$, $\frac38\cdot22p$, $\frac14\cdot26p$, $\frac38\cdot26p$, $\frac1{12}\cdot54p$ and $\frac{11}{24}\cdot54p$ are whole numbers.
We can see by inspection (or by Python bashing) that $p=4$ is the smallest such number. For $\frac38\cdot22p$, $\frac38\cdot26p$ and $\frac{11}{24}\cdot54p$ to be whole numbers, $p$ needs to be a multiple of $4$. Fortunately, $p=4$ makes the other three values whole numbers. So $x=88$, $y=104$, and $z=216$, and these add up to $n=408$.