If you haven’t looked at the puzzle yet, check out the Coffee Bean Puzzle first.
Okay. So the operations allowed were described like this:
- Pull out two beans at random. If the two beans are the same color, replace them with a white bean.
- Pull out two beans at random. If the two beans are different, replace them with a black bean.
You can rephrase the “take two beans out and then do something” to be a single action like this:
- Operation 1 above where both beans were white: remove one white bean.
- Operation 1 above where both beans were black: remove two black beans and put in a white bean.
- Operation 2 above: remove one white bean.
Note that 1 and 3 are the same operation. So there are really only two operations. You pull out two beans at random to see what to do, and then:
- If the beans were both white or were different colors, then take out one white bean and put the other back.
- If the beans are both black, remove them and put in a white bean.
Now it’s clearer: you can put in a white bean, and you can remove a white bean, but you can only remove black beans in pairs. Given that, the last bean is determined by the even-ness or odd-ness of the black beans. If they are odd in number, the last bean will be black. Otherwise, because the last black beans will be a pair, which under rule 2 produces a white bean, the last bean will be white.
There is another method of solving this (the one I actually used) that is either overcomplicating the situation, or perhaps offers better insight. I’m trying to devise a more complex variant of this puzzle to see which is the case.