问题
Given an array of odd numbers or even numbers, how can one efficiently get pairs of this array whose XOR == 2?
For example:
arr = [4,10,2,6,8]
pairs are: [(4,6), (8,10)] #4^6 == 2, 8^10 == 2
Or:
arr = [5,9,3,7,11]
pairs are: [(9,11), (5,7),]
I did this to get them (brute-force)
for i in combinations(inev,2):#inev is the list of indices (positions of the numbers in the array)
if not (arr[i[0]] ^ arr[i[1]]) & 1 and (arr[i[0]] ^ arr[i[1]]) == 2:
print arr[i[0]], arr[i[1]] #I print the pair
来源:https://stackoverflow.com/questions/52239393/knowing-the-xor-of-odd-number