First attempt at problem 10. Correct, but needs optimization.