Problem 011 refactored