Skip to content

Instantly share code, notes, and snippets.

@ra312
Created June 6, 2020 14:15
Show Gist options
  • Save ra312/22d5239f210494520034e6e5ec1ae579 to your computer and use it in GitHub Desktop.
Save ra312/22d5239f210494520034e6e5ec1ae579 to your computer and use it in GitHub Desktop.
counting pairs with bitwise product
import itertools
def countPairs(arr):
# Write your code here
count = 0
for i, j in itertools.combinations(arr, 2):
v = i & j
if v != 0 :
if (v % 2 == 0) | (v == 1):
count+=1
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment