This is the CodeEval problem #237, and here I give my Python 3 solution.
The sample provided could be easily converted in these python test cases:
def test_provided_1(self): self.assertTrue(solution('64 6e 78 | 100101100 11110')) def test_provided_2(self): self.assertTrue(solution('5e 7d 59 | 1101100 10010101 1100111')) def test_provided_3(self): self.assertFalse(solution('93 75 | 1000111 1011010 1100010'))After splitting the input line, we just have to use the built-in function int(), passing as second parameter the expected base:
hexes = [int(x, 16) for x in data.split()] bins = [int(x, 2 ) for x in data.split()]And then it is just a matter of comparing the sum() of the two lists:
return sum(hexes) <= sum(bins)I have pushed the test case and the python script to GitHub.