maximizing-xor: bruteforce python implementation
This commit is contained in:
parent
532e290407
commit
1bac478cb3
1 changed files with 22 additions and 0 deletions
22
algorithms/bit-manipulation/maximizing-xor/maxXor.py
Executable file
22
algorithms/bit-manipulation/maximizing-xor/maxXor.py
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/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))
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue