This notebook was prepared by Donne Martin. Source and license info is on GitHub.
See the HackerRank problem page.
See the HackerRank problem page.
See the HackerRank problem page.
class Solution(object):
def max_xor(self, 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
%%writefile test_maximizing_xor.py
import unittest
class TestMaximizingXor(unittest.TestCase):
def test_maximizing_xor(self):
solution = Solution()
self.assertEqual(solution.max_xor(10, 15), 7)
print('Success: test_maximizing_xor')
def main():
test = TestMaximizingXor()
test.test_maximizing_xor()
if __name__ == '__main__':
main()
Overwriting test_maximizing_xor.py
%run -i test_maximizing_xor.py
Success: test_maximizing_xor