|
|
|
|
|
by foota
330 days ago
|
|
It's a solution to the problem: given a list of n-1 unique integers 1 through n, find the missing integer. The trick is that when you xor all of the numbers in the list together and then xor that with the xor of 1 through n, the result is the missing number. |
|
XOR[0...x] = (x&1^(x&2)>>1)+x*(~x&1)
Of course, you don't have to do this with xor, you can do it with just addition (mod wordmax) and the well known identity attributed to gauss will support you.