Python solution for Problem 11