给定一个由奇数或偶数组成的数组,一个人如何才能有效地获得XOR == 2的该数组对?
例如:
arr = [4,10,2,6,8]
pairs are: [(4,6), (8,10)] #4^6 == 2, 8^10 == 2
或者:
arr = [5,9,3,7,11]
pairs are: [(9,11), (5,7),]
我这样做是为了让他们(蛮力)
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