hackerrank-solutions/algorithms/bit-manipulation/maximizing-xor/maxXor.py

22 lines
458 B
Python
Executable file

#!/usr/bin/env python3
def maxXor(L, R):
result = 0
maxA = L
maxB = L
for A in range(L, R+1):
for B in range(A, R+1):
tmp = A ^ B
if tmp > result:
maxA = A
maxB = B
result = tmp
return (maxA, maxB, result)
if __name__ == "__main__":
L = int(input())
R = int(input())
A, B, M = maxXor(L, R)
print("{}^{} = {}".format(A, B, M))