Brilliant Computer Science level 5 entry solution in Python 2