-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathbitmagicPART2.py
More file actions
37 lines (32 loc) · 745 Bytes
/
bitmagicPART2.py
File metadata and controls
37 lines (32 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# n convert it into binary
def intToBin(n):
return str(bin(n))[2:]
# bin to int
def binToInt(s):
return int(s,2)
# kth bit set from right
def kthbit(n,k):
print(str(bin(n))[2:])
if n & (1 << (k-1)):
print("SET")
else:
print("NOT SET")
# [5,3,2,3,2,1,5]
# every number occurs twice
# we need to find the number which occurs only once
# n^n = 0
# n^0 = n
def findsingleoccur(arr):
res = arr[0]
for i in range(1,len(arr)):
res = res ^ arr[i]
return res
t = int(input())
while t:
arr = list(map(int,input().split()))
#binstring = intToBin(n)
#integer = binToInt(binstring)
#print(n,binstring,integer,n==integer)
#kthbit(n,k)
print(findsingleoccur(arr))
t=t-1