Solved Problem 10; solution is a bit slow though