Do Problem 10 in Python. Sort of slow - needs optimization.