# Sunday Times Teaser 2805 – Greek Urns

### by Michael Fletcher

#### Published: 26 June 2016 (link)

I have three Greek urns. I took some balls (consisting of an odd number of red balls and some black balls) and I placed one or more balls in the first urn, one or more in the second, and the rest in the third. If you chose an urn at random and then a ball at random from that urn, then overall there would be a 50 per cent chance of getting a red ball.

Then I moved some black balls from one of the urns to another. In this new situation, if you chose an urn and then a ball there was a 75 per cent chance of getting a red. In fact, with this set of balls and urns it would be impossible to get a higher percentage than that.

How many red balls and how many black balls were there?

Here is a manual solution.

To make the probability of withdrawiing a red ball 3/4, $$r+2$$ red balls and $$3r$$ black balls must be placed in the three urns in the following way: red $$(r,1,1)$$ and black $$(3r,0,0)$$.

When $$x$$ black balls are moved from urn one to urn two, the distribution of black balls becomes: $$(3r-x,x,0)$$, making the probability of drawing a red ball: $(r/(4r-x)+1/(1+x)+1/0))/3$ which must be 1/2. This gives the following quadratic for $$x$$:$x^2-(2r+1)x+6r=0$with the solution:$\frac{(2r+1\pm\sqrt{(2r-5)^2-24})}{2}$ For integer $$x$$ the expression in the square root must be a perfect square (say $$c$$), giving: $(2r-5)^2-c^2 = 24$If $$f$$ is a factor of 24, we have:$\begin{array}{lcl}2r-5+c &=&f \\2r-5-c&=&24/f\end{array}$which gives the solutions for $$r$$ and $$c$$ in terms of $$f$$ as:$\begin{array}{lcl}r&=&(24/f+f+10)/4 \\c&=&(24/f-f)/2\end{array}$Trying the factors of 24 gives only one solution: $$r=5$$ and $$c=1$$ with $$x=5$$ or $$x=6$$.

Hence there are 7 red balls and 15 black balls.

@Brian,

You don’t need to store red and blk in max_vals.
I think you mean formulae 2r – 5 + c = f and c = (f – 24/f) / 2

Regarding first line of the manual solution:

red(r, 3s, t) black(r, s, 0) also has an overall 75 per cent chance for drawing a red (r, s and t all positive).

Jim has published this puzzle as well:

https://s2t2.home.blog/2021/07/22/teaser-2805-greek-urns/

Some of my comments also apply to your program as well (like using r1 > 0)