Solution for problem #10 (again, very slow)