From 1bac478cb33d2827cebcd100f5e2a67d5c3510e7 Mon Sep 17 00:00:00 2001 From: Dmitry Kokorin Date: Mon, 12 Sep 2016 15:41:31 +0300 Subject: [PATCH] maximizing-xor: bruteforce python implementation --- .../bit-manipulation/maximizing-xor/maxXor.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 algorithms/bit-manipulation/maximizing-xor/maxXor.py diff --git a/algorithms/bit-manipulation/maximizing-xor/maxXor.py b/algorithms/bit-manipulation/maximizing-xor/maxXor.py new file mode 100755 index 0000000..2ec28cf --- /dev/null +++ b/algorithms/bit-manipulation/maximizing-xor/maxXor.py @@ -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)) + +