Problem 10 - very slow solution