A box contains p white balls and q black balls. Beside the box
there is a pile of black balls. Two balls are taken out from the
box.

If they are of the same colour, a black ball from the pile is put into
the box.

If they are of different colours, the white ball is put back into the box.

This procedure is repeated until the last pair of balls are removed from the box and one last ball is put in.

What is the probability that this last ball is white?

Source: Australian Olympiad 1983

(In reply to

re: Half a solution (partial spoiler), finished by Jer)

Ah yes, of course, I almost had it.

However Jer, you are not correct that the last two balls must be white if p is even. They could both be black. What is true is that the last two balls must match, because you cannot have one white and one black ball. Therefore, the last ball which is put in must be black.

So, If p is odd, the probability is 1. If p is even, the probability is 0.