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

I didn't look at the other comments for 3 days now, trying to glean the solution myself. I finally succeeded - but it required me making a computer simulation to bang my head against and see the light.

Charlie solved it and stated the answer well. I will just say it my own way: On each draw the total number of balls goes down one. Whites are diminished by each draw, either by two or none at all. Thus, starting with an even number of whites will always leave none, while starting with an odd number of whites must leave a remainder of one. The reasons for taking two or no white balls out each time scarcely matters.

There are two categories of puzzles I like most: those that are easily stated but devilish to solve, and those that seem impossible but are really easy if you look at them correctly. This falls in the second category. I just wish I could see the smile on one competitor in the exam room when he/she realized the solution!

*Edited on ***October 20, 2018, 1:36 am**