It is a classical puzzle by Edsger Dijkstra. Not quoting the original problem but changing it into bag and balls, the puzzle is:
A bag contains some black and white balls. The following process is to be repeated as long as possible (assuming that we have infinite supply of black and white balls).
- Randomly select two balls from the bag. If they are the same color, throw them out, but put an extra black ball in.
- If they are different colors, place the white one back into the bag and throw the black one away.
As you can see that each iteration of the process reduces the number of balls in the bag by one. Also, repetition of the process must terminate with exactly one ball in the bag. The question is:
What, if anything, can be said about the color of the final ball based on the number of white balls and the number of black balls initially in the bag.