Given the sequence [0 .. 255]
If a single value is removed, the xor of the remaining values produces that missing value.
However, if two values are removed, This no longer works.
A. Why does this happen for the single-value case?
B. Can this be extended to quickly find one of N missing?
I came across this question while working on a application that uses a bit field to give every value a unique bit to flip. I was curious if a more optimal/efficient solution existed to find gaps. My observation was based on generating full sequence with a single gap.
Let g be the sequence [0..255] with a single missing value q
Fold(x xor y, g) = q
Let h be the g with another missing value r
Fold(x xor y, t) = distance between q and r
So if r or q is 0 it does result in a correct answer.
Distance here is in a modular 256 sense.
I found it interesting that the single missing value seems to just drop out. But for two values all I get is the delta.
So a very efficient solution exists for a single missing value. No bit field or searching required. But when two or more values are missing finding one of them using this method no longer works.