Completing Problem 10 but I need a better way of doing it since it is really slow