This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges).
See the HackerRank problem page.
See the HackerRank problem page.
See the HackerRank problem page.
Complexity:
Note:
In [1]:
def max_xor(lower, upper):
result = 0
for l in range(lower, upper + 1):
for u in range(lower, upper + 1):
curr = l ^ u
if result < curr:
result = curr
return result
In [2]:
%%writefile test_maximizing_xor.py
from nose.tools import assert_equal
class TestMaximingXor(object):
def test_maximizing_xor(self):
assert_equal(max_xor(10, 15), 7)
print('Success: test_maximizing_xor')
def main():
test = TestMaximingXor()
test.test_maximizing_xor()
if __name__ == '__main__':
main()
In [3]:
%run -i test_maximizing_xor.py