Skip to content

Instantly share code, notes, and snippets.

@muthhukumar
Created August 15, 2020 13:30
Show Gist options
  • Save muthhukumar/a42368a0d786f3dfad143d479f67711a to your computer and use it in GitHub Desktop.
Save muthhukumar/a42368a0d786f3dfad143d479f67711a to your computer and use it in GitHub Desktop.
import itertools
n = int(input())
inputs = list(map(int, input().split()))
max_binary_equivalence = max(inputs)
def Binary(n):
binary = []
while n != 0:
binary.append(n % 2)
n = n // 2
s = ""
for i in binary[::-1]:
s += str(i)
return s
mbe = len(Binary(max_binary_equivalence))
def BinaryMBE(n, dp = 0):
s = Binary(n)[::-1]
if dp != 0 and dp > len(s):
for _ in range(dp - len(s)):
s += '0'
s = s[::-1]
return s
def one_and_zero_count(n):
arr = []
for j in i:
for k in BinaryMBE(j, mbe):
arr.append(k)
one_count = arr.count('1')
zero_count = arr.count('0')
return [one_count == zero_count, one_count, zero_count]
combination = sum([list(map(list, itertools.combinations(inputs, i))) for i in range(len(inputs) + 1)], [])
count = 0
for i in combination:
if len(i) > 0:
if one_and_zero_count(i)[0]:
count += 1
print(BinaryMBE(count, mbe))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment