Truth table mystery
For which values of the booleans a and b is this expression true? What is the usual name for it?
(a and not b) or (not a and b)
Show hint
There are only four combinations of two booleans. Write out a table.
Show solution
It is true when exactly one of a and b is true: (True, False) and (False, True). This is exclusive or (XOR).
In Python you can write it as a != b for booleans, or a ^ b. XOR turns up in parity checks, simple ciphers and the "find the number that appears once" trick.
Want a problem like this every day? See today's problem and keep a streak going.